|
The code you've posted doesn't have anything that removes the current message from the queue, so peeking will always return the same message. You either need to add something to receive messages from the queue (which will remove them), or use a message queue cursor to peek at messages past the first one.
|
|
|
|
|
Na na!!!
You miss judged my statements.
The problem is messages are coming conitinuously and i must use an asynchronous receive to trigger it on my application that a message has been received i don't wish to receive the messages but only peek at them, only when they are available in the queue. Peek only single message when it is available and then when the next is available peek at that and discard the older message which is intended to be received by some other service running after it.
So any work around that!!!
|
|
|
|
|
Right, I followed what you were saying. The problem is if you use Peek (or BeginPeek) without any arguments, it will always return the first message available in the queue. You must use a message queue cursor to move within the queue while peeking.
Here's some quick code to peek at all messages coming through the queue in a separate thread using a cursor.
public static void Main() {
queue = GetQueue();
ThreadPool.QueueUserWorkItem(new WaitCallback(QueueMonitor),queue);
}
void QueueMonitor(object SourceQueue) {
MessageQueue queue = (MessageQueue)SourceQueue;
Message msg = null;
Cursor cursor = queue.CreateCursor();
PeekAction action = PeekAction.Current;
try{
while(true) {
msg = queue.Peek(MessageQueue.InfiniteTimeout, cursor, action);
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPeekedMessage), msg);
action = PeekAction.Next;
}
}catch(Exception ex){
}finally{
}
}
void ProcessPeekedMessage(object PeekedMessage) {
Message msg = (Message)PeekedMessage;
}
I opted to use the ThreadPool to run a thread instead of using the BeginPeek/AsyncCallback style. Someone here may have a better solution using that instead (from what I read, they're essentially doing the same thing). I also opted to thread the processing as well so the monitoring thread doesn't get blocked while the message is being worked on.
|
|
|
|
|
Hi everyone,
I am kind of just after a bit of advice and opinon. I am making a podcatcher in C#(duh that's the board I am posting to ). I don't have any problem with the coding yet(touch wood) however I am trying to decide how best to store the information on the subscribed to podcasts and their relevant episodes. Straight away I thought about saving it as an xml file, podcast RSS downloaded as an xml file, fairly easy convert of my object into XML and then back to saving it. But then I thought it could get a bit iffy when it comes to duplicates. I don't really want to have to traverse the entire XML doc to find duplicates, and ensure that they don't happen. So thinking ahead i created my podcast episode objects with a unique id. but then i don't really want to save my subscription list in a db either, that seems to me to be overkill. The only other thing is to just output the subs list into a text file, then read each object in and ensure that there are no duplicates from what ever storage container i put them in(ArrayList prob ) This seems a bit naff too though.
I don't know I think maybe I am just rubbish at making a decision , but I would appreciate some other people's input into how they would store the data.
Thanks in advance
Cads
|
|
|
|
|
Senseicads wrote: i don't really want to save my subscription list in a db either, that seems to me to be overkill
Go for a database with a small footprint. You can use SQL CE or Microsoft Access; both a relative small, and it would be easy to define a primary key or a unique-constraint
I are Troll
|
|
|
|
|
It just seems so OTT to use a Database to store what is basically RSS Feed data.
[edit]Although saying that I didn't think of using Access...hmmm...just not sure...
|
|
|
|
|
Senseicads wrote: It just seems so OTT to use a Database to store what is basically RSS Feed data.
Lots of RSS-data, and I guess that you want to search it fast
Senseicads wrote: Although saying that I didn't think of using Access
I'd go for SQL CE; it can't create nifty reports like Access does, but all that you need is a searchable datastore.
I are Troll
|
|
|
|
|
Lol I think you are right. I pretty much just need a datastore. Thanks for the guidance
Ian
|
|
|
|
|
My pleasure
|
|
|
|
|
SQL CE is obsolent. SQL Server Compact[^] is the current rendition
only two letters away from being an asset
|
|
|
|
|
Cool, thanks for the update
|
|
|
|
|
Eddy Vluggen wrote: Microsoft Access;
only two letters away from being an asset
|
|
|
|
|
Yeah, that's the standard-reaction, you get the some one when talking about Visual Basic 6. Many a brownfield is a combination of those two
Access empowered a lot of non-programmers to create small business-applications. It got abused as a server-database, and is still one of the better reporting engines (You'd only need to free runtime-version of Access and Microsoft Word)
Yeah, they were great products in their time, and they still haven't vanished.
I guess that they're like Windows, or Democracy. We know it sucks, but there is no better alternative available yet.
I are Troll
|
|
|
|
|
how many records will you need? 10? 100? 1000? simply don't know?
IMO for anything above 30 it takes a database to do it well. It's the most scalable approach. And it's easier than XML if you ask me.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I guess it would be fairly open ended as to how many podcasts that a user could subscribe to. I never really thought about how many records there would be( starting to sound like the amateur I am here! )
Actually thinking about my own usage, I am subscribed to about 10 different podcasts each with say 10-20 episodes in it. Certainly over your 30 records mark! lol
Is that a good rule of thumb? More than 30 use a db?
Thanks
Cads
|
|
|
|
|
Senseicads wrote: Is that a good rule of thumb? More than 30 use a db?
No it isn't. The real rule of thumb is: few ==> file; many ==> database. But that could be considered a bit vague. So I volunteered 30. Don't pin me down on the number.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
No from now on it will be Luc said 30!!! its too late now! its in print and everything!
|
|
|
|
|
Right. So start choosing your DB, your SQL dialect, your server, and your backup service.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I have this kind of error and I don't understand what can be the problem.
Is someone can help me to solved the problem or to understand what it's mean
Here is my code.
this.userinfos1.RoleID = mainData.roleid;
And this error message appears
NullReferenceException was unhandled
|
|
|
|
|
either userinfos1 or mainData is null for some reason. Put a breakpoint on the line and hover over it with the mouse to see which.
|
|
|
|
|
My best guess is userinfos1 is declared as an array, however you haven't yet created an array.
In .NET arrays take three steps: declaration, creation (with the "new" keyword), and stuffing.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
mainData variable seems to have a null.
|
|
|
|
|
Hi,
I need to add x509Extension to x509Certificate2 class but i dont know how (i read somewhere its not possible so im not sure about it).
Lets imagine this code :
X509Certificate2 cert;
X509Extension ext;
cert.Extensions.Add (ext);
byte [] b = cert.export (X509contentType.Cert);
X509Certificate2 cert2 = new X509Certificate2 (b);
// Here comes the problem ... there is no my extension in the cert2 collection.
Btw: I create it by calling c function CertCreateSelfSignCertficate. Is there any way to add my extension to created certificate or the only way to add it is in the creation time?
i rack my brain with this issue for several days so any help would be very appreciated.
thanks
Libor
|
|
|
|
|
Hi,
my problem is the following: I wrote a program that downloads lots of images from the internet (not porn though :P). Anywhoo, when i had the entire program in one thread it was not very responsive during the downloading (i used application.doevents in between the downloading cycles). When i added a separate thread for the downloading part i could move the windows around on the screen quickly and with no problems. What i don't quite understand is the why.
What controls the movement of the program window during execution? Does the main thread decide how much processor time it gives for the program and how much for the movement? When does the main thread end? Does it ever end, due to the fact that it has to handle button clicks?
Does main thread end when there are multiple threads? If it does end before the downloading thread, how can the smooth window movement during downloading be explained (as there is still only one thread running?).
TY
|
|
|
|
|
Hi,
when your app starts, it has only one thread, the "main" or "GUI" thread. It gets more if and when you create them (Thread, ThreadPool, BackgroundWorker) or perform asynchronous I/O operations (e.g. SerialPort.DataReceived).
All GUI operations (including window moving and resizing) are handled on the main thread; that mainly consists of executing the event handlers you provide, such as Form_Load, Button_Click, and many others. The events that trigger them are collected in an "input queue" and executed one by one, so one handler has to finish before the next one can start; that is why a window won't move if it is in the middle of a lengthy operation inside say a Button_Click handler. With one exception: when Application.DoEvents() is called often enough, everything may appear to be running smoothly (in reality you are running a big risk of instability, one should avoid DoEvents most of the time).
To keep the GUI responsive one should limit the execution time of each handler to a small timespan, say 30 milliseconds. Anything that always or sometimes may take more should be delegated to another thtead; otherwise the user will dislike the way he looses control of the GUI.
And the main thread comes to an end when it has no more work to execute, that typically happens when the main form gets closed causing the Application.Run() method to return in the static Main() method (inside file Program.cs); unless you started some threads that still haven't finished executing their code and didn't get marked with IsBackground=true.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|