|
 input is: 1,2,3,4,5,6,7,8,9,10 (several times)
namespace Test
{
public class SyncQueue<T>
{
private Queue<T> queue;
private object readerLock;
private object queueLock;
private AutoResetEvent dataAvailable;
public SyncQueue()
{
this.queue = new Queue<T>();
this.readerLock = new object();
this.queueLock = new object();
this.dataAvailable = new AutoResetEvent(false);
}
public void Enqueue(T item)
{
lock (queueLock)
{
queue.Enqueue(item);
Console.WriteLine("Enqueued Item: " + item);
}
dataAvailable.Set();
}
public T Dequeue()
{
lock (readerLock)
{
if (queue.Count == 0)
{
dataAvailable.WaitOne();
}
lock (queueLock)
{
return queue.Dequeue();
}
}
}
}
public class Tester
{
SyncQueue<int> myQ = null;
public Tester(SyncQueue<int> queue)
{
myQ = queue;
}
public void ProcessMessages(object obj)
{
while (true)
{
Console.WriteLine(myQ.Dequeue());
}
}
}
public class Program
{
static void Main(string[] args)
{
SyncQueue<int> myQ = new SyncQueue<int>();
Tester t1 = new Tester(myQ);
Tester t2 = new Tester(myQ);
Tester t3 = new Tester(myQ);
ThreadPool.QueueUserWorkItem(new WaitCallback(t1.ProcessMessages));
ThreadPool.QueueUserWorkItem(new WaitCallback(t2.ProcessMessages));
ThreadPool.QueueUserWorkItem(new WaitCallback(t3.ProcessMessages));
while (true)
{
string[] snumbs = Console.ReadLine().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string snumb in snumbs)
{
myQ.Enqueue(int.Parse(snumb));
}
}
}
}
}
the exception is: Invalid Operation Exception - queue is empty.
any idea?
thanks,
|
|
|
|
|
It was pretty easy to debug when you posted actual test code. The problem lies within AutoResetEvent. WaitOne will not wait till its state isn't resetet. add this:
dataAvailable.Reset()
dataAvailable.WaitOne();
|
|
|
|
|
ok thanks,
but isn't autoResetEvent supposed to change it's own state automatically after WaitOne()?
i thought that's what it is doing...
maybe i don't understand the difference between auto and manual reset events. can anyone explain?
thanks again.
|
|
|
|
|
|
yeah you're right! something is missed up...
that's what made me be confused about my code at first place...
weird.... thank anyway though!
|
|
|
|
|
please help me I want to print saerch results,if I can send them to microsoft report it's better and if I could print it or save it in pdf format it would be good for my work.if one of them is possible please tell me!
|
|
|
|
|
both of them are possible.
For pdf ITextSharp
For ms reports(Crystal I assume) I can't help you => never used them.
But Ging(Google+Bing == Ging) could help 
|
|
|
|
|
thank you for your answer I will test it and tell you about it . but why I have to forget?
|
|
|
|
|
Ive been building an application that reveals information on what image files have been accessed by any given user
RegistryKey OurKey2 = Registry.Users;
OurKey2 = OurKey2.OpenSubKey(userID + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSavePidlMRU\\" + valuename);
foreach (string valuename2 in OurKey2.GetValueNames())
{
DataGridViewRowCollection rows = this.dataGridView3.Rows;
System.Byte[] strByte = (System.Byte[])OurKey2.GetValue(valuename2);
System.Text.Encoding enc = System.Text.Encoding.Unicode;
string myString = enc.GetString(strByte);
rows.Add(myString, valuename);
}
This gives me "䐟ᩇ夃㽲䒧얉镕毾" etc all gibberish
The actual value viewed in the registry doesnt exactly make sense but you can still read it
Can anyone tell me how to either just read a sensible value from it or how to find out what encrypt/encoding the registry uses on these values?
It also seems to only be reading the first part of the value
Thanks in advance Carl
|
|
|
|
|
I don't know what the content of these items are on your system, but on mine they appear to contain complex structures. Thus you cannot just read them as a byte array and convert to Unicode. You need to understand the structure of these keys and convert them according to the different parts of their structures. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
The competition[^] does not really know, but CodeProject[^] seems to know (yes, it is in C++).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Sunday, February 28, 2010 5:49 PM
|
|
|
|
|
|
Hi,
How can I make a safe cross thread call for a textbox to set the 'text' of the textbox?
|
|
|
|
|
Use the InvokeRequired and if required Invoke() it. Else normal assignement.
|
|
|
|
|
Hi,
Do you got a sample for me?
Thanks in advance!
|
|
|
|
|
something like:
if(this.txt1.InvokeRequiered){
Invoke(new MethodInvoker(delegate
{
this.txt1.Text = ComputedValue();
}));
Something like that.
[Edit]This example assumes that you created your working thread
from the UI thread[/Edit]modified on Sunday, February 28, 2010 12:50 PM
|
|
|
|
|
You can either disable cross thread exception or you can use delegates.
My advice, use delegates!
Cheer's,
Alex Manolescu.
|
|
|
|
|
Nice to here of you again. Now romanian stuff.
Ce mai zici?
N-ai m-ai raspuns. In ce parti ale tarii esti?
Oras. In ce domeniu(specific) lucri?
Back to english => I'm working on a System.Terror implementaion. Would anyone like
to help me in my effort?
It curently implements the ISpanihInquistion , LiquidNitrogen , AbsDoDoubtlyNitro and
many many others such as IDoublyDoubtAnything , ISuck , IPlz ,
IWantFerrari and so on.
[Edit]
And of course IForgatToMention that IAmInsane .
[/edit]
cheersmodified on Sunday, February 28, 2010 1:36 PM
|
|
|
|
|
Hi Mosule,
i've been busy with my work
i'll send you a pm.
cheers
|
|
|
|
|
I do pretty much the same as Moshu except I invoke the method again from within the method if required (recursion) and repass the parameters rather than hardcoding them.
private void SetText(Control control, string text)
{
if (InvokeRequired)
Invoke(new MethodInvoker(delegate { SetText(textBox, text); }));
else
control.Text = text;
}
|
|
|
|
|
Hi,
How do you make the control enter that method?
Shouldn't there be some sort of callback declared?
|
|
|
|
|
However you like, you can call that method from a callback if desired.
If you are wanting to handle an event from a different thread without calling another method then just match up to the event signature as you do in your event handler to invoke the handler on the correct thread.
Dave<br>
<font size="-1">Tip: <a href="http://www.codeproject.com/tips/55555/Pass-value-between-forms-using-events.aspx">Passing values between objects using events (C#)</a></font><br>
<font size="-2">BTW, in software, hope and pray is not a viable strategy. (<a href="http://www.codeproject.com/Members/Luc-Pattyn">Luc Pattyn</a>)<br>Why are you using VB6? Do you hate yourself? (<a href="http://www.codeproject.com/script/Membership/View.aspx?mid=6556">Christian Graus</a>)</font>
|
|
|
|
|
This[^] deals with it.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Thank you guys, it works! 
|
|
|
|
|
oracle uses a list of values component
i searched internet but i couldn't find anything similar in C# by the same name
is there other name for this component
any links or resources would be helpful
thanks in advance
excuse my bad language
|
|
|
|