|
-
May 12th, 2015, 12:36 PM
#5
Re: Multithreaded class
Well, you don't. That would defeat the purpose of the threading. After all, if you were to write a line like this:
Dim someVar = SomeFunction()
someOtherVar = someVar
You would expect that SomeFunction would be executed and the return would be put into someVar. The next line would then do something with someVar. However, what you are doing is launching a different process that will do a bunch of work. You certainly don't want execution to stop on the thread.Start line until the process completes, as that would defeat the whole purpose of threading. Instead, you want execution to launch the process and move right on to the next line. If the next line were to use the return from the function, as in my example, it wouldn't work, because the process was still running. The time when that variable becomes available for the original process isn't known, so you can't know when the next line could be executed (unless you wrote some code to respond to some event from the thread, or joined the thread, or something like that). Therefore, you can't usefully return anything from a thread. What you'd have to do is put the information into a variable at class or form scope (such as your list), and have the thread signal the UI thread that it had completed. Tasks makes that a bit easier because you can chain actions together such that when the Task completes it has the next steps that are to be taken.
As for passing in the address of a method, that's all it is: An address to a function. That simply doesn't have enough information to allow for arguments to be passed, nor can it. Take a look at this link for examples of how you can pass arguments (except that it doesn't appear to be passing anything at all, but just relying on non-local variables):
https://msdn.microsoft.com/en-us/library/wkays279.aspx
My usual boring signature: Nothing
 
Tags for this Thread
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
|