[newbie] Thread problem

G

Guest

hi,

I just created a class, that sometimes needs to contact a webservice on the
internet. Now, as the network connection of the local computer isn't always
available, I need this call to be asynchronous, in a way that it doesn't
block the whole program.

That's why I tried to implement some sort of multithreading: the function
that needs to be called asynchronously needs some strings as arguments, but I
cannot find a way to pass arguments to my thread routine....

Second, I have a question concerning the life cycle of thread objects: When
I create a thread object in a sub (by 'new'), start a thread and immediately
quit the sub - is the thread I started still executing - or killed?

By the way, I thought of implementing the whole stuff by a timer (that is
called after 10 ms) - if that gives me the opportunity to avoid the use of
'real' threads - or makes paramter handling easier....is this a good idea?

Thanks,

Peter
 
J

Jon Skeet [C# MVP]

Peter Schmitz said:
I just created a class, that sometimes needs to contact a webservice on the
internet. Now, as the network connection of the local computer isn't always
available, I need this call to be asynchronous, in a way that it doesn't
block the whole program.

Does the webservice API you're using not have BeginXXX and EndXXX
methods for asynchronous execution?
That's why I tried to implement some sort of multithreading: the function
that needs to be called asynchronously needs some strings as arguments, but I
cannot find a way to pass arguments to my thread routine....

See http://www.pobox.com/~skeet/csharp/threads/parameters.shtml
Second, I have a question concerning the life cycle of thread objects: When
I create a thread object in a sub (by 'new'), start a thread and immediately
quit the sub - is the thread I started still executing - or killed?

It's still executing. The Thread object will at least be available in
the executing thread until it finishes.
By the way, I thought of implementing the whole stuff by a timer (that is
called after 10 ms) - if that gives me the opportunity to avoid the use of
'real' threads - or makes paramter handling easier....is this a good idea?

No - I'd use real threads if I were you, assuming the answer to the
first question is "no".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top