|
-
Nov 6th, 2009, 09:02 AM
#8
Re: Calling a function on a different thread
Objects don't run on any specific thread. I think people have got this idea because controls have an affinity for a specific thread but even controls don't run on any particular thread. You can access any object on any thread at any time; even controls. The only real restriction is that you can only access the handle of a control on the thread that created it. That's where the thread-affinity of controls comes from. Anything that doesn't require accessing a control's handle can be done on any thread you like.
As for other types, they don't even have the thread-affinity that controls do, so what thread they get created on is generally completely irrelevant. That is certainly the case for a FileSystemWatcher. The thread it's created on makes no difference whatsoever because every time it raises an even it will be raised on a different thread anyway. The FileSystemWatcher class uses the ThreadPool and will raise an event on whatever ThreadPool thread happens to be available at the time. For that reason, starting a new thread from a FileSystemWatcher's event handler is also pointless. Why create a new thread when you're already on a different thread to begin with?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|