|
Probably not - IIRC none of the .NET Collections are intrinsically thread safe, and they should all be locked.
Either use the .NET Queue[^] with a lock or homebrew a safe version. If you are just using a single in-feed and a single out-feed, you don't need to use locking if you write it correctly.
One way is to use an array, with two indexes - input and output. If insert only affects the input, and remove only affects the output, the only time they need to both be checked is for a full/empty test, which shouldn't need a lock - it would if you used more than one input source, or more than one remover.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: IIRC none of the .NET Collections are intrinsically thread safe
Actually, .NET 4 introduced the System.Collections.Concurrent namespace[^], which includes a ConcurrentQueue .
However, IIRC there's the potential for a delayed garbage collection - the queue keeps a reference to the object even after it's dequeued until it's been overwritten in the queue's buffer. This becomes more of an issue with a large-capacity queue. Our workaround was to use the Mono implementation of the ConcurrentQueue instead (it doesn't have this problem).
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Didn't know that - have a five!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: thread safe
New in .NET 4, http://msdn.microsoft.com/en-us/library/dd997305.aspx[^]
[Edit]
Never mind. OP already posted that.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
yes this was my intention to have to indexes one for read, one for write,
and because it is in a Handlerfunction it should be executed very fast so I will use a vector - as the circular list (or Buffer).
I will try this solution first, after the other with the Thread safe collections.
thx
|
|
|
|
|
probably I need some kind of lightweight lock, bacause the call to the Handler can come realy fast and mess up with my array index, which is already done in ConcurrentQueue<t> Class.
Even if I use a state bit on every element the index could be messed up by another call just before it is used.
I have been wondering how it is implemented.
Would be possible this class: ConcurrentQueue<t> Class to e implemented using just Interlock class
witout any SpinWait or while loops?
modified 31-Jul-12 6:46am.
|
|
|
|
|
how to create monthly calendar in c#?
|
|
|
|
|
|
plz give me appropiate answer.
|
|
|
|
|
sutapa das wrote: plz give me appropiate answer.
I'm not sure but maybe this link can help you.
How to create your monthly calendar.
Moreover, you don't have to post the same question to get your answer faster.
It won't work here.
|
|
|
|
|
Why not just use one of these[^], or one of these[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Well, how "appropriate" the answer is depends entirely on what the hell you mean by "create monthly calender".
That could mean anything! Are you trying to come up with a control that lets you input a date, a data range over months, something to display an entire month, storing data based on some month requirement, ... ??? WHAT?
|
|
|
|
|
Hi,
Is it possible to make a shortcut in application level not control level so no matter where the focus is or which form is active, shortcut will be invoked?
|
|
|
|
|
You can use the PreviewKeyDown event to see what key is pressed at the Form level.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
As a side note to your answer you also need to set the KeyPreview property to true for the form.
|
|
|
|
|
Shortcuts generally work whichever control on a form has focus, unless the control explicitly steals that character (i.e. text boxes with Ctrl+C/X/Z/V). I think you need to put a shortcut handler on every form, though, if you want app-wide ones.
|
|
|
|
|
Yes, it is, but you will have to go on treacherous ground to do so (needs some unmanaged code). Take a look at keyboard hooks, more specifically RegisterHotKey and UnregisterHotKey , both from user32.dll .
Google it further, there are a lot of threads detailing how this can be achieved, for instance here[^], or here[^]
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
If your application has an MDI form, you can create a menu item with the intended code and assign a shortcut to it. It would work "universally" in your entire application.
|
|
|
|
|
Hello
Does anyone have already experienced the BeginGetResponse illutrated in the Microsoft example ?
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetresponse.aspx[^]
My need will be to make an hrttprequest in asynchronous mode. To not let the user wait for a response that can be processed in backround.
First I was thinking to use a BackroundWorker, then I see that begingetresponse example
But it react exacly as the BeginResponse : when I step over it wait a few seconds to get the response.
So maybe I misunderstand something but I don't see any advantage of this method ??
Thank for your help
|
|
|
|
|
When you run it, is it timing out? Or is it receiving a response?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
BeginGetResponse will execute the method in the AsyncCallBack asynchronously. If you do like in the MSDN example then it will wait for that asynchronous operation to finish
this is the code that will cause it to wait and also implements a timeout method so if the asynchronous operation takes to long it will end the asynchronous operation.
ThreadPool.RegisterWaitForSingleObject (result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), myHttpWebRequest, DefaultTimeout, true);
allDone.WaitOne();
|
|
|
|
|
Thank for the answer
But it seems that the BeginGetResponse itself takes long to come back
// Start the asynchronous request.
IAsyncResult result=
(IAsyncResult) myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallback),myRequestState);
I test it a few times yesterday
But today I try again and now it return immediately !
Even if I cut the network connexion !
I probably miss something !
Some told me that I have to wrap this code example in a dedicated thread !
But if so I dond see the advantage of using the BeginGetResponse
|
|
|
|
|
I'm thinking you must have missed something initially, BeginGetResponse should return immedialtely.
The only reason I would see to run that in a dedicated thread is if you want to worry about a timeout or want to ensure the asynchronous method completes like the example, as the method will block waiting for the ManualResetEvent to be set. Using the ManualResetEvent is for situations where you can't process the next step until that process has completed.
|
|
|
|
|
Thank you Trak4Net
Ok ... maybe I was too tired yesterday
I will try again tonight
But indeed I'm expecting that BeginGetResponse return immediately whatever the connexion state !
|
|
|
|
|