Threading Scneario!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, I have a ClassA and a worker ClassB.
in my ClassA I have a method which calls the following routine
for(int idx=0;idx<10;idx++)
{
ClassB ob=new ClassB();
ThreadPool.QueueUserWorkItem(new WaitCallback(ob.Exec));
}

I want to know/signal when all the Worker ClassB are done?

TIA
 
Thanks my friend

Nicholas Paldino said:
Vai2000,

There is an article in MSDN magazine this month that will help you out
here. It is the .NET Matters section, titled "ThreadPoolWait and
HandleLeakTracker" and you can find it at (watch for line wrap):

http://msdn.microsoft.com/msdnmag/issues/04/10/NETMatters/default.aspx

It's the first question in the section.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vai2000 said:
Hi All, I have a ClassA and a worker ClassB.
in my ClassA I have a method which calls the following routine
for(int idx=0;idx<10;idx++)
{
ClassB ob=new ClassB();
ThreadPool.QueueUserWorkItem(new WaitCallback(ob.Exec));
}

I want to know/signal when all the Worker ClassB are done?

TIA
 
Hello everyone,
I am building a service that stores table rows in a collection.

The service will ocasionally "refresh" it's collection with the rows that
have changed since the last "refresh"

I am trying to us the SQL timestamp (equivalent to a binary(8) column) to
determine which rows have changed:
So I want to:
Save the timestamp
Query for records that have a timestamp greater than the saved timestamp
Save the greatest timestamp

I don't seem to understand how to get the conversions\datatypes correct:

//I want to start off at zero:
byte[] _timeStamp= {0x00000000};

//Use SQLHelper from Data Access Application Block
//This works as long as _timeStamp is byte[]
SqlDataReader dr =
SqlHelper.ExecuterReader(connString,"GetMonitoredRows_sp", _timeStamp);

//I have tried byte and byte[].
byte[] _tempTS;
while (dr.Read())
{
 
Next said:
//I have tried byte and byte[].
byte[] _tempTS;
while (dr.Read())
{
.
.
.
//Tried several conversions here. This doesn't work because
//it doesn't return a byte[]
_tempTS = Convert.ToByte(dr["timestamp"].ToString());

//Can't compare strings; Can't compare byte[]. How should
//I make this comparison
if( _tempTS > _timeStamp)
{
_timeStamp = _tempTS;
}


Try this :

byte[] _tempTS; // stick with a byte array.
....
_tempTS = (byte[]) dr["timestamp"];
// timestamp columns should be of type : byte[], so the cast should work.

To make the comparison, you'll have to compare the byte array one byte
at a time. If you want a human readable string representation of the
byte array, you could use a routine like this :

private string ConvertBytesToString(byte[] b)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append("0x");
for (int i = 0; i < b.Length; i++)
{
sb.Append(b.ToString("X2"));
}
return sb.ToString();
}

i.e.

string str = ConvertBytesToString(_tempTS);

If this doesn't help, try the dotnet adonet newsgroup -
they'll probably be of more help.

HTH,
Stephen
 
Back
Top