SPESHOW


i had an error in this line. may i know how to correct it..

threadField.Join(new System.TimeSpan(MiliSeconds * 10000));



Re: threading

Alex Yakhnin MSFT


What's the error and a context






Re: threading

ScubaSteve20001

Well, if you are using the Compact Framework, the thread class's Join method does not take a Timespan object as an argument. It takes an integer value that represents the maximum number of milliseconds that you want it to wait for the thread to join on.





Re: threading

SPESHOW

i still dont quite understand..





Re: threading

SPESHOW

Error 1 The best overloaded method match for 'System.Threading.Thread.Join(int)' has some invalid arguments C:\Documents and Settings\itcu\My Documents\Visual Studio 2005\Projects\DeviceApplication1\DeviceApplication1\SupportClass.cs 256 17 CHHPmax

Error 2 Argument '1': cannot convert from 'System.TimeSpan' to 'int' C:\Documents and Settings\itcu\My Documents\Visual Studio 2005\Projects\DeviceApplication1\DeviceApplication1\SupportClass.cs 256 34 CHHPmax





Re: threading

ScubaSteve20001

Say that you want to wait on your thread to end for up to 5 seconds (aka 5000 milliseconds). It would be like this:

myThread.Join(5000)





Re: threading

SPESHOW

oh i got it. so for this threadField.Join(new System.TimeSpan(MiliSeconds * 10000)); , i will have to change to

threadField.Join(10000); right..

what if it was nanoseconds

and also it doesnt allow + sign..

threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100));





Re: threading

ScubaSteve20001

Since the Join method takes an integer (int) value that represents the number of milliseconds, you need to convert nanoseconds into milliseconds, to do that you will need to divide your number of NanoSeconds by 10^6 to convert that into milliseconds.

Instead of:

threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100));


it would be:


threadField.Join(MiliSeconds * 10000 + NanoSeconds * 100)


This is assuming that your converting everything so that they are in milliseconds.