By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Does callback run on worker thread.

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.