473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Does callback run on worker thread.

Hi all,

I am having one confusion regarding invoking method through threading.

I have delcared one delegate. and i have one class which has parameter
of type delegate which i declared.

I have passed address of function which needs to be invoked when my
thread procedure complete.

So my question is will callback run on worker thread or on UI thread.

And if i want to update controls which i there on form in callback. Do
i need to lock that control before updating its text. Like do i need to
call invoke method on that control to provide synchronization for
updating text control so as to prevent two threads to simultanously
update same control.

Please correct me if i am wrong.

Thanks in advance.

Sep 27 '06 #1
5 2297
"archana" <tr**************@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
I have passed address of function which needs to be invoked when my
thread procedure complete.
When you say "invoke", do you mean you actually call Invoke?
So my question is will callback run on worker thread or on UI thread.
Assuming you are using Invoke or BeginInvoke, the callback itself will run
on the UI thread. If you use Invoke, your invoking thread will block until
the UI thread has handled the delegate. If you use BeginInvoke, a worker
thread will do that instead.
And if i want to update controls which i there on form in callback. Do
i need to lock that control before updating its text. Like do i need to
call invoke method on that control to provide synchronization for
updating text control so as to prevent two threads to simultanously
update same control.
As long as you are using Invoke or BeginInvoke, the invoked method will run
on the correct thread and you need not worry about any other
synchronization.

Pete
Sep 27 '06 #2

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:12*************@corp.supernews.com...
| "archana" <tr**************@yahoo.comwrote in message
| news:11**********************@i3g2000cwc.googlegro ups.com...
| I have passed address of function which needs to be invoked when my
| thread procedure complete.
|
| When you say "invoke", do you mean you actually call Invoke?
|
| So my question is will callback run on worker thread or on UI thread.
|
| Assuming you are using Invoke or BeginInvoke, the callback itself will run
| on the UI thread. If you use Invoke, your invoking thread will block
until
| the UI thread has handled the delegate. If you use BeginInvoke, a worker
| thread will do that instead.
|

No worker thread get's involved here, the message is posted and the caller
simply returns without blocking.

Willy.
Sep 27 '06 #3
And just to add... Which means the delegate is always run by the only UI
thread (hence no cross-thread operation).

--
William Stacey [MVP]

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:us**************@TK2MSFTNGP02.phx.gbl...
|
| "Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
| news:12*************@corp.supernews.com...
|| "archana" <tr**************@yahoo.comwrote in message
|| news:11**********************@i3g2000cwc.googlegro ups.com...
|| I have passed address of function which needs to be invoked when my
|| thread procedure complete.
||
|| When you say "invoke", do you mean you actually call Invoke?
||
|| So my question is will callback run on worker thread or on UI thread.
||
|| Assuming you are using Invoke or BeginInvoke, the callback itself will
run
|| on the UI thread. If you use Invoke, your invoking thread will block
| until
|| the UI thread has handled the delegate. If you use BeginInvoke, a worker
|| thread will do that instead.
||
|
| No worker thread get's involved here, the message is posted and the caller
| simply returns without blocking.
|
| Willy.
|
|
Sep 29 '06 #4
Hi all,

Thanks for reply.

Now my doubt is if callback is running on UI thread, if in call back i
checked currentthread.name property it is giving me name of worker
thread and not name of UI thread.

Can someone tell me what is reason behind this behaviour.

Any help will be truely appreciated.

Thanks in advance.

Oct 4 '06 #5
Please show some code to help us see behavior.

--
William Stacey [C# MVP]

"archana" <tr**************@yahoo.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
| Hi all,
|
| Thanks for reply.
|
| Now my doubt is if callback is running on UI thread, if in call back i
| checked currentthread.name property it is giving me name of worker
| thread and not name of UI thread.
|
| Can someone tell me what is reason behind this behaviour.
|
| Any help will be truely appreciated.
|
| Thanks in advance.
|
Oct 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob Rock | last post by:
Hello, exploring more and more the .NET framework I've seen that threads are often employed by the framework, for example in: - callback methods on timers - async operations (async receives...
2
by: David | last post by:
Hi all, I am new to .Net environment. I have created a flat non-COM DLL from Visual C++ 6.0. It stores up a function pointer from caller, create a worker thread via WIN32 API, and then call...
0
by: Dominick Baier | last post by:
Hi, impersonation effectively means that you setting your current thread in the security context of your client. When you invoke a web service asynchronously, .net grabs a thread from the...
4
by: | last post by:
Hello, I have a worker thread ( a shared method in a class) that needs to callback to another (monitoring) class on certain events. I have been unable to figure out how to pass the callback...
2
by: Marcus Kwok | last post by:
I have processing code (I'll call it the "model") written in native unmanaged pure C++, and I have put a GUI on top of it written using Windows Forms (.NET 1.1). The GUI is used to set the...
2
by: Morgan Cheng | last post by:
By default, ThreadPool has 25 worker threads per CPU and 1000 IO threads for each process. I am wondering how CLR managed to allocate IO asynchronous tasks to IO thread and other asynchonous tasks...
7
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort()...
5
by: gazza67 | last post by:
Hi, Does anyone know how to check for when a sound has finished playing? I am currently using the SoundPlayer, there doesnt seem to be any event for this - am I missing something? Gary
2
by: billsahiker | last post by:
I wrote a test program to help understand asynchronous calls in c#. I have a working VB.NET app that uses a similar technique but I cannot get it to work in c#. The errors I get and the code below....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.