|
Hi,
I'm broadcasting a meesage to a port and wait to receive response from all the devices that are connecting to this port.
So I put the receiveFrom() in a while loop. My problem is when there are no more device the application stuck on the receiveFrom (as it doesn't receive...).
I think that I should set a timeout but how to do that?
Thanks,
|
|
|
|
|
Aren't you running ReceiveFrom() on a separate thread?
|
|
|
|
|
|
You can run it on a separate thread. So that the other application areas won't be affected and your application won't get stuck when there no messages to receive.
|
|
|
|
|
Thanks but this is not what I asked for.
Anyway I have found a way to do this.
Thank you.
|
|
|
|
|
Hi All,
How can i express this statement in C# code:
ZipCode is within 1000—1999
the data type of ZipCode is string and i can't change it to int.
if ((ZipCode >= 1000) && (ZipCode <= 1999))
but appraently it wasn't working. and i also did this:
if ((int)(ZipCode >= 1000) && (ZipCode <= 1999))
but it wasn't working either.
Thanks
|
|
|
|
|
Try this:
int code = int.Parse(ZipCode);<br />
if((code >= 1000) && (code <= 1999))<br />
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|
|
Since you have it in string, using int.Parse may result in error when you have other than numbers in the string. So always use int.TryParse
bool IsInRange(string zipCode){
int code;
return (int.TryParse(zipCode, out code) && code >= 1000 && code <= 1999);
}
|
|
|
|
|
if ((Convert.ToInt32(ZipCode) >= 1000) && (Convert.ToInt32(ZipCode) <= 1999))
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
Why not simply compare them as strings?
if (ZipCode >= "1000" && ZipCode <= "1999")
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
is there any source-code link to capture youtube videos?
Thanx in advance
(Riaz)
|
|
|
|
|
|
I have a list box that I am populating from a file. My file has a reference ID and I want to display text in the list box and associate it with the ID. This is easy when I display the ID in the list box but I want to hide it without just change the text color to match the text box. Any help would be great.
|
|
|
|
|
Your question is not clear. Please explain it more.
|
|
|
|
|
It's not very clear what you want to do.
If you want to add all items but have no text for items that match a particular ID then you have two options. Both require overriding the ToString method of the objects you are adding to return string.Empty for the ones you want empty.
You can then either add the object itself to the listbox (handy cause you can cast back to the object itself later)
or
When you add the items, call the ToString method and use the ID property to set the Tag.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Sorry guys for not being clear.
Here is what I am doing. In the list box I want to show say a list of first names. Each first name has an ID that goes with it. Say John is number 18. If the user clicks on John I want to be able to look up number 18 associated with that John. If I add John to the list box origianlly like this (listBox1.Items.Add(ID[i] + " " + Name[i]);) then getting the 18 is not a problem. But I want to only show to the user John not the ID on each record. Like I said I could change the font color on the ID and not show it that way but I was wondering if there might be another way to do it.
|
|
|
|
|
The list box holds a collection of objects not strings so you can add anything to it. The text it displays is controlled by the ToString method or in it's absence, the base.ToString method. At the moment you're adding a string so the string.ToString method is being called.
Instead, if it's not already - make each person an instance of your own class. In the class, override the ToString method to return just the text you want and add each instance to the list box. To retrieve the ID, cast the listbox item to your class and you will then be able to access that instance's properties including ID.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Or even cooler, write a new listbox control that contains a new property called "Hidden" that you can set from the form.
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello
I am using Event in my program. Below i am giving the Code thats being used, but somehow this is not working.
// Class from triggering Event
Public class Manager
{
public static Manager myManager;
public delegate TestEventDelegate (object sender, int i);
public event TestEventDelegate TestEvent;
public Manager Initialize() // This initilaize is called
//from another class which gets 1st called
{
if(myManager == null)
myManager = new Manager();
else
myManager;
}
public void RaiseEvent(object sender, int i)
{
TestEventDelegate temp = TestEvent;
if(temp != null)
temp(this, i);
}
// Now inside a function from where i am triggering the Event
public void InitializeEvent()
{
TestEvent = new TestEventDelegate(RaiseEvent);
TestEvent(myManager, 10);
}
}
// Now in another Class
public class Reciever
{
public Reciever() // Constructor
{
Subscribe(Manager.Initialize());
}
public void RecieveEvent( object sender, int i)
{
MessageBox.Show("Event Success!!!");
}
public Subscribe(Manager mgr)
{
mgr.TestEvent += new Manager.TestEventDelegate(RecieveEvent);
}
}
So this is the code i am using. It compiles fine. But doesn't work.
Any idea?
The "Initialize()" in the triggering class makes that class Singleton.
|
|
|
|
|
I can't find where you are calling InitializeEvent() method?
Donosguy wrote: mgr.TestEvent += new Manager.TestEventDelegate(RecieveEvent);
Donosguy wrote: TestEvent = new TestEventDelegate(RaiseEvent);
You have hooked TestEvent in the Subscribe method. You are hooking it again in InitializeEvent() which will overwrite the previous one. You can do something like
Public class Manager
{
public static Manager myManager;
public delegate TestEventDelegate (object sender, int i);
public event TestEventDelegate TestEvent;
public static Manager Initialize() {
if(myManager == null)
myManager = new Manager();
else
myManager;
}
public void InitializeEvent()
{
if(TestEvent != null)
TestEvent(this, 10);
}
}
public class Reciever
{
public Reciever()
{
Manager manager = Manager.Initialize();
Subscribe(manager);
manager.InitializeEvent();
}
public void RecieveEvent( object sender, int i)
{
MessageBox.Show("Event Success!!!");
}
public Subscribe(Manager mgr)
{
mgr.TestEvent += new Manager.TestEventDelegate(RecieveEvent);
}
}
|
|
|
|
|
Using C#, how do I call the queue method printQueue to print out to rtbox a list of the (Batch No, weight) pairs stored in a data queue?
|
|
|
|
|
I think you might be mixing objects here.
There is the System.PrintQueue class, which represents a queue of printer jobs queued up by Windows to submit to a printer; and there are Queue objects (System.Collections.Queue), which you use to hold collections of data.
There is no "print" method for a Queue object.
|
|
|
|
|
amm actually refering to queue method and not "print" method.
|
|
|
|
|
It's still not clear what it is you want to do.
1. do you have data sitting in a System.Queue object?
2. would you like to Dequeue that queue, and put a copy of the text/values there in a text box?
|
|
|
|