|
|
Hi All,
In my application one thread waits for AutoResetEvents from various other threads.
I'm using WaitHandle.WaitAny(eventArray) to wait for any one of the events to become signalled then perform a switch on the returned index. My problem is that when 2 or more events are signalled at the same time I only get the array index for one event and the other signalled events are effectively lost. How can I ensure I respond to the other signalled events? It would have been better if subsequent calls to WaitHandle.WaitAny provided the index to these other signalled events on subsequent calls but it doesn't work like that.
Got any suggestions?
Thanks
Paulmodified on Thursday, February 18, 2010 3:55 AM
|
|
|
|
|
paul_b_baker wrote: It would have been better if subsequent calls to WaitHandle.WaitAny provided the index to these other signalled events on subsequent calls but it doesn't work like that.
Are you sure?
An AutoResetEvent remains signalled until it is used to satisfy a wait. WaitHandle.WaitAny is no different in that respect to WaitOne . So if two events are signalled at the same time, one will win the race to satisfy the wait and WaitAny will return it's index. The next WaitAny will succeed immediately and return the index of the other event.
Unless you mean that it is one event that is being signalled twice and one of the signals is being lost. This is a known problem with AutoResetEvent . If this is the case, you will have to use a different synchronization mechanism.
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
Nick thanks but I'm quite sure I've got it right.
If two seperate events become signalled WaitHandle.WaitAny only returns the single lowest index and subsequent calls won't return the other signalled event indexes because, (I'm guessing here) AutoResetEvents are reset when the thread waiting on them runs. So my thread detects one event and runs but clears two or more events!?
Paul
|
|
|
|
|
Nick,
You're right.
In my code I added a check to see if a second event had been signalled when processing the first event. My check involved a call to WaitOne which reset the second event so (obvious after reading your post) I never saw it set in the main WaitAny loop!
I'm eating humble pie right now.
Thanks again.
Paul
|
|
|
|
|
Just some advice for future message posting...
Nick won't see that reply (because you replied to yourself) unless he visits the forum again and looks for this thread.
Further, when you edited your original post to change the title to "SOLVED", you should have put the solution in the original message as well. In a really long thread, very few people will hunt for the "solution" if it's buried deep in the message traffic..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
No worries, we've all done it! I'm glad you got your bug fixed anyway.
If you can, I would do all threading development on VS2010. The RC is available and includes ( well at least the Ultimate version does ) some very useful new tools. In particular, the concurrency profiler shows you when waits are satisfied and by which thread, which would have been useful in this case.
If you really want to ensure correct code, there is also a CTP of a tool called Chess:
http://research.microsoft.com/en-us/projects/chess/[^]
It systematically explores synchronization interleavings by running tests ( it's a dynamic tool ). It's got a bit of a learning curve and you have to write the right tests, but it's worth it if you are unsure if your program is correct.
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
Hi All,
I want to find how many elements have blank value and the number of that element using LINQ.
I dont want to iterate the array.
Please guy guide me.
Regards,
Sunil G.
|
|
|
|
|
It depends upon what you mean by "blank" but:
String[] foo = { "", "Hello", "", "World", "How", "are", "You", ""};
Console.WriteLine(foo.Count(x=> string.IsNullOrEmpty(x)));
Should give you some idea.
You'll need to change the predicate x=> string.IsNullOrEmpty(x) to suit your needs.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Thanks for your quick reply
It prints : 3.
I also want the index of the element.
In this example it is 0,2 and 7..
How is it possible?
Thanking You,
Sunil G.
|
|
|
|
|
Sunil G wrote: How is it possible?
Iteration. Something has to iterate the array, LINQ is just doing that under the covers.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
"Blank" in what way? Array's don't have "blanks" in them, although an array of type T may contain elements with the value default(T) - is that what you want to find?
If so, you might do this: (!!untested!!)
static int CountEmpty<T>(IEnumerable<T> data)
{
return data.Count((T item) => object.Equals(item, default(T)));
}
Someone will have to iterate the array though, even if you don't do it yourself. Without looking at the whole array you can never know that there are no "blanks" left in the part that you skipped.
Except of course if you keep a count of how many elements of the array you changed from blank to non-blank (minus the ones you changed back to "blank") in the first place.
|
|
|
|
|
Good answer. I'd was thinking of null rather than default(T). Regards,
Rob Philpott.
|
|
|
|
|
I don't like to give up control; so I would write the iteration rather than have Linq do it.
|
|
|
|
|
Its your wish.
|
|
|
|
|
this.comboBox[store_num] = new System.Windows.Forms.ComboBox();
this.comboBox[store_num].FormattingEnabled = true;
this.comboBox[store_num].Location = new System.Drawing.Point(7, box_location );
this.comboBox[store_num].Name = "comboBox" ;
this.comboBox[store_num].Size = new System.Drawing.Size(68, 21);
this.comboBox[store_num].TabIndex = 0;
this.comboBox[store_num].DataSource = storeNameArray;
//
// textBox3
//
this.textBox[store_num] = new System.Windows.Forms.TextBox();
this.textBox[store_num].Location = new System.Drawing.Point(106, box_location);
this.textBox[store_num].Name = "textBox3";
this.textBox[store_num].Size = new System.Drawing.Size(76, 20);
this.textBox[store_num].TabIndex = 1;
priceArray[store_num] = this.textBox[store_num].SelectedText;
panel1.Controls.Add(this.comboBox[store_num]);
panel1.Controls.Add(this.textBox[store_num]);
store_num += 1;
box_location += 20;
I allow the user to add new ComboBoxes everytime they click add item. Now if there are two comboBoxes, when they select an item from the second one, it changes the first one as well. How do I stop that from happening, so each comboBox has there respective selections.
|
|
|
|
|
Since you didn't supply your own BindingNavigator for each combobox, the default navigator is used for all controls on the form.
The solution is easy. Create a BindingSource for each combobox. Set the DataSource property of the BindingSource to the data source you're currently using, then set the combos DataSource to the BindingSource you just created.
ComboBox1 ----> BindingSource1 ----> Data
ComboBox2 ----> BindingSource2 ----> Data
...
|
|
|
|
|
Hi,
using the smtpclient.SendAsync method, I want to know how much byte (or the percentage)
has been sent out of total bytes.
I didn't found a way to get status information from the client.
Is there another way (for example over the sockets interface) to retrieve these missing information
if yes, how ?
Thank you for your time
Frank
|
|
|
|
|
The SmtpClient doesn't report any progress information, so you cannot do what you want using the SmtpClient class. You'll either have to find a 3rd party library that does what you want or write your own SmtpClient class.
|
|
|
|
|
Thank you Dave,
what you say I already know. But please say where to get these process information and how.
Solutions ?
Frank
|
|
|
|
|
Search for 'RFC 821' on Google (to start with.You'll find out there are more RFC's about sending email).
|
|
|
|
|
|
i have already developed a app which will run in two machine and send the screen shot of machine 1 to machine 2 and i am showing the scree shot of machine 1 on the picturebox through a application which is running in machine 2. so now i want to control mouse and keyboard of machine 1 programatically.
so i need concept. i have some idea like whenever i will move my mouse & click on picture box then i will just send some info like mouse move cordinate and click to the app which is running in machine 1. then machine 1 will move the mouse pointer to the location & click according to my info.
but the problem is if i send the mouse cordinate then two machine may have different resolution. in this case how could i handle this situation.
suppose if i send mouse move cordinate and click then how could i place mouse pointer on right object if machine 1 have different resolution.
so please help me with idea & sample code.
thanks in advance.tbhattacharjee
|
|
|
|
|
are use pictuerbox for showing the remotdesktop?
|
|
|
|
|
yes i will use pictuerbox for showing the remotdesktop screen. please help me. tbhattacharjee
|
|
|
|