|
Hi,
I want to display the messages from Queue in consoleapplication.I am able to read the queues.But while displaying, if i had 6 messages in queue and in that i am able to display only 3.Please help me out in solving this.
My code is as follows:
string QueueName = ".\\Private$\\TestQ";
MessageQueue.EnableConnectionCache = false;
//// open the selected message queue
this.messageQueue = new MessageQueue(QueueName, QueueAccessMode.Receive);
while (true)
{
System.Messaging.Message message = new System.Messaging.Message();
MessageQueueTransaction msgTx = new MessageQueueTransaction();
MessageDetails messageDetails = null;
try
{
msgTx.Begin();
message.Formatter = new BinaryMessageFormatter();
message = messageQueue.Receive(new TimeSpan(0, 0, 0, 10), msgTx);
if (message.Body != null)
{
messageDetails = (MessageDetails)message.Body;
Console.WriteLine(messageDetails.ApplicationName + "\t" + messageDetails.ThreadName + "\t" + messageDetails.Status + "\t" + messageDetails.TimeStamp);
}
msgTx.Commit();
messageQueue.BeginReceive();
}
Thanks in Advance
|
|
|
|
|
is messageQueue subscribed to receive the callback from the BeginReceive() call? if not that'll probably discard every other message in the queue.
|
|
|
|
|
I've tried to capture the desktop with the cursor image using different codes and none manages to draw the IBeam cursor. If I use the Cursor.Current, I always get the waitcursor; using API, I get the correct cursor. Is there a workaround?
|
|
|
|
|
Nothing, guys? From what I've seen during my google searches, this is a common problem so I think there must be a workaround. I know that Ibeam is a xor cursor, but I don't know how to get the xor mask using CursorInfo.
|
|
|
|
|
when should we use Convert.ToDouble and Double.Parse
Thanks
|
|
|
|
|
Convert.ToDouble[^] allows you to convert other types to a Double.
Double.Parse[^] parses a string and attempts to convert it to a Double (although normally Double.TryParse[^] would be better).
Learn how to use MSDN and Google - the links I've given were first in the lists on Google!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Why did you feel the need to post this question in no less than 7 different forum?? It's no longer likely your ever going to get an answer to this question seeing as you saw fit to do what everyone hates -> SPAM this site with your question. Pick a single forum most appropriate for your subject, like General Discussions in your case, and post your question ONCE!
|
|
|
|
|
...
Blog link to be reinstated at a later date.
|
|
|
|
|
I have some code that we use to parse the contents of a folder and perform actions based on file dates. We would now like to do the same over our internal network to a location such as http://server.company.com:8080/files. Unfortunately, the DirectoryInfo method does not support this type of path. Is there a similar method that can be used for this type of path?
|
|
|
|
|
I am attempting to write code that sinks an event with only an object reference and the event name - no type information. I write a generic event handler function:
public void ComponentEventHandler(object o, EventArgs e)
{
// handle generic event
}
Then I wrote some code that attaches any event to this event handler function
protected void SinkControlEvent(Control ctrl, string eventName)
{
EventDescriptor event = TypeDescriptor.GetEvents(ctrl)[eventName];
Delegate del = Delegate.CreateDelegate(typeof(System.EventHandler), this, "ComponentEventHandler");
event .AddEventHandler(ctrl, del);
}
This works fine when the event I'm sinking has the standard function signature. However, I get an exception when the event has a derived EventArgs parameter. For example, trying to sink the following event would cause a type mismatch exception:
public event void ValueChanged(object sender, ValueEventArgs e);
The exception is "Invalid event handler for ValueChanged event". Of course 'ValueEventArgs' inherits from EventArgs, so I don't understand why this isn't a valid handler.
Some things to note:
1. You can, in code, assign an untyped event handler to a typed event. Somehow the compiler figures it out.
2. I tried changing my code such that I attach an untyped function to a typed delegate, but that also threw an exception.
Delegate del = Delegate.CreateDelegate(event.EventType, this, "ComponentEventHandler");
Thanks,
Aaron Stibich
|
|
|
|
|
astibich2 wrote: public void ComponentEventHandler(object o, EventArgs e)
Could you not change this to
public void ComponentEventHandler<T>(object sender, T e) where T : EventArgs
|
|
|
|
|
That looks a lot like the EventHandler< T> class
|
|
|
|
|
Well, I thought so, but I can't see what he's trying to do that you can't accomplish normally.
|
|
|
|
|
Hello TCP gurus!
It's me again, standing in a the corner of a room with wet paint all around me.... Any help would be appreciated.
I have a dictionary
public class DataImage : Dictionary<string,>
which has been working wonderfully for me. But now I find that when I have a problem when adding values using the Item property.
DataImage<string,> modImage = new DataImage<string,>();
...
modImage["xxx"] = "yyy";
I need to have some additional actions occur. In particular, DataImage contains some private data that needs to be updated whenever an element is added or removed. I have the required code in the Add() and Remove() methods, but I also need that logic to occur when the dictionary is accessed using its Item property.
I would like to do something akin to
public override string Item[key]
{
get { return base[key]; }
set
{
base[key] = value;
changeOtherStuff(key, value);
}
}
I looked at this page (http://msdn.microsoft.com/en-us/library/9tee9ht2.aspx[^]), but couldn't see how to write the necessary code from it. I also searched online, but to no avail.
Clive Pottinger
Victoria, BC
|
|
|
|
|
cpotting wrote: I also searched online, but to no avail.
They hide that information in the documentation[^]
led mike
|
|
|
|
|
Thank you Mike - exactly the syntax I needed. Now I can hang from ceiling and continue painting the floor...
Clive Pottinger
Victoria, BC
|
|
|
|
|
Few observations:
- when defining Item property (indexer), I believe you should provide type of the key parameter
- indexer is defined using this keyword
- default indexer is not marked virtual so you should use new keyword
So the code should be something like the following
public class DataImage : Dictionary<string,sometype> {
...
public new sometype this[string key} {
get {...
Hope this helps,
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thank you too, Mika
Clive Pottinger
Victoria, BC
|
|
|
|
|
sorry. The definition of DataImage should say "string,string", but the display is dropping the second "string". And for some reason, I can't get in to edit to the message.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Hi fellows:
How can I restirct only integers to be entered inside the propertygrid value field. I tried looking into this matter by wasn't quite succesfull. I hope your suggestion can help me.
Thanks
|
|
|
|
|
Search for GridItem. Will Implement one row in a PropertyGrid.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
I couldn't find much related to GridItem to control user input. Would you be kind enough to provide me with some examples or code or perhaps a useful resource.
Thanks
|
|
|
|
|
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
GridItem selectedItem = e.ChangedItem;
if (selectedItem.Label == "Text")
{
if (selectedItem.Value.ToString().Contains('a'))
selectedItem.PropertyDescriptor.SetValue(propertyGrid1.SelectedObject, e.OldValue);
}
}
Hope it can help
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
My office is testing a bunch of folks who have applied for Java jobs. I don't know head and tails of the language other than that its syntax is stolen from here and there (I'm still partyin' with MFC/Win32, yay!). My buddy was the invigilator and got the questions' sheet. This was one of the easiest assignments, and shockingly, only 3 out of the 14 people that attempted this problem finished it correctly on time. Some took more than 45 minutes but got it right, and others didn't solve it at all! I tried it for the hell of it beat the time by 29 minutes, finishing at 16 minutes (C/DevCPP), which I guess is not bad. Post your times here, and see if you can bring it down below 16 minutes.
Q7. (Note: You cannot answer Questions 8, 11 and 14 if you are answering this question. Pick another 2 from the rest).
Write a command-line program as follows:
First the program will take as input a +ve integer from the user, let's call it
the TARGET.
It will then take in a set of +ve integers from the user, and here the user gets
to specify how many integers he/she wants to enter. Let's call this set the
RANGE.
Now the program should compute as follows:
- Find all combinations in the RANGE, the sum of which add up to the
target. Print such combinations at the command prompt. In a combination,
repeats are not allowed. i.e. (x + x + y) = TARGET is forbidden. Every element
in the combination must be unique.
- In case a user enters a RANGE element greater than the target, it should be immediately
discarded and the user must be prompted for the element again.
- Order shifted cases don't count. i.e. (x+y) and (y+x) being printed
separately is unnecessary and MUST be avoided.
- In case no combinations exist, the program should report so.
- Add exception handling code where necessary.
Example Run:
Enter Target: 15
How many set elements?: 5
Enter Element1: 7
Enter Element2: 8
Enter Element3: 12
Enter Element4: 3
Enter Element5: 22
Sorry. That element is larger than your target. Try again.
Enter Element5: 4
Combinations are:
1] 7+8
2] 8+3+4
3] 12+3
Time: 45 mins.
(At the top of the source file, please comment in your ID details along with the reference number at the back of the day-card you were provided by the examiner. Write your Full Name, ID key, TDC number and most importantly the reference number. Good luck.)
modified on Tuesday, November 4, 2008 2:13 PM
|
|
|
|