|
You can write a protected or private OnEvent method. Its not that much code and should be done quickly even for some events by copy-and-paste. Furthermore, the methods may be useful, if you later on add more intelligence to the dummy or implement the final class.
private void OnEvent(EventArgs e)
{
if (this.Event!= null)
this.Event(this, e);
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
thank u for answering but i wish to still send the string until i click the cancel button . these ways (while 1==1) , while(true),... keep the program not responding. i have to do task manager and stop the program can u help me to solve this problem?again this is my code . thank u all.
private void OK_Click(object sender, EventArgs e)
{
string str;
ExceptionLabel.Text = "";
sp.BaudRate = 9600;
sp.DataBits = 8;
try
{
if (sp.IsOpen == false)
sp.Open();
str = "*" + fan.Items[fan.SelectedIndex].ToString() + "&" + light.Items[light.SelectedIndex].ToString() + "@" + water.Items[water.SelectedIndex].ToString() + "#";
sp.WriteLine(str);
textBox.Text = str;
}
catch (System.Exception ex)
{
ExceptionLabel.Text = ex.Message;
}
}
private void cancel_Click(object sender, EventArgs e)
{
sp.Close();
this.Close();
}
|
|
|
|
|
Create your loop in a new Thread .
And don't open a new topic, you can continue the discussion in your previous topic.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I suggest you use a timer (preferrably a System.Forms.Timer) to periodically perform
your serial port stuff once, have your OK button start the timer and your Cancel button
stop te timer.
Alternatively, provide a bool variable "portRunning"; let your start button set
portRunning true and make it create a new thread that contains a while(portRunning) loop
with your serial port stuff, and let your Cancel button set portRunning false.
I prefer the timer approach since then you achieve an upper bound for the amount
of data that gets transmitted per second.
PS: none of these will run infinitely, your computer (or Windows) will come to an end sooner
or later...
Luc Pattyn
|
|
|
|
|
Hi, i wish to create an infinite loop to send a string to an I/O port infinitly can anyone help me please? my code code is:
private void OK_Click(object sender, EventArgs e)
{
string str;
ExceptionLabel.Text = "";
sp.BaudRate = 9600;
sp.DataBits = 8;
try
{
if (sp.IsOpen == false)
sp.Open();
str = "*" + fan.Items[fan.SelectedIndex].ToString() + "&" + light.Items[light.SelectedIndex].ToString() + "@" + water.Items[water.SelectedIndex].ToString() + "#";
sp.WriteLine(str);
textBox.Text = str;
sp.Close();
}
catch (System.Exception ex)
{
ExceptionLabel.Text = ex.Message;
}
}
private void cancel_Click(object sender, EventArgs e)
{
sp.Close();
this.Close();
}
|
|
|
|
|
|
while (1 == 1)
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
or the old C++ goody:
for(;;)
|
|
|
|
|
In VS 2005, I'm trying to add a menu item to the Project context menu, so that when I do command line stuff for the project output I can just right-click and select, "Command Prompt", and a command prompt opens up in the right folder.
Explore the commands and menubars etc. on saturday, I could not identify to which object I must add the command etc. Can anyone help me with this?
Apologies if this is too OT, but I couldn't find a VS 2005 forum.
|
|
|
|
|
Hi,
I am trying to expose my .NET 2.0 class as a COM type using the following
attributes for the attributes
[ClassInterface(ClassInterfaceType.None)]
[Guid("8D0240AD-1BBE-4831-8214-39DD46A4A797")]
I have the "Register for COM Interop" build property set to true. I also have two functions in the class to register and unregister the COM with the registry. But when i try to build it in VS.NET 2005, i get the following error "XXX.dll does not contain any types that can be registered for COM Interop" and "XXX.dll does not contain any types that can be Unregistered for COM Interop". The same code works perfectly in VS.NET 2003. Anybody know of any reasons why this is happeneing or what i am doing wrong?
Thank You,
A.Ansari
Asadullah ansari
|
|
|
|
|
Hi All,
Is there anyway to access the reuuning instance of an object in a application from another application. Both the applications are built using C#. I have tried using the GetActiveObject, but it seems used for COM objects. Is there any method available for managed objects. I don't want to use remoting.
Thanks in advance
Diana.
|
|
|
|
|
Hi diana it's very nice question. I like this kind of developement.
I think This possible through Interprocess communication.
Actually i have no time for implement this thing.
Plz refer this url it may be assist.
http://msdn2.microsoft.com/en-us/library/aa446520.aspx
http://msdn2.microsoft.com/en-us/library/aa365574.aspx
Plz inform what kind of you have exact need.
If u face further problem plz inform me.....
-- modified at 12:17 Monday 29th January, 2007
Parwej Back...............DON of Developer.......
Parwej Ahamad
g_parwez@rediffmail.com
|
|
|
|
|
Hi Parwej,
Thanks for the reply.
I want to get hold of an object from a different application for automated testing purpose.
Diana.
|
|
|
|
|
I'm writing an application on Windows XP which is tested on Windows 2000 and 2003 Server. It works fine on XP and Windows 2003, but on 2000 it behaves differently. The ListView component does not show Groups for example. Is there any way to get ListView to behave the same on each platform?
|
|
|
|
|
Hello!
I'm trying to findout how to catch event between changing rows in ListView . I don't want to use ListView.SelecetIndexChanged , I need to catch an event in time of changing. Do anyone of You know how to do it?
|
|
|
|
|
By 'changing' do you mean editing a list item? There is the AfterLabelEdit or BeforeLabelEdit events...
If you mean changing as in selecting a different item, then what is wrong with SelectedIndexChanged ?
|
|
|
|
|
Problem is more complicated. In my Form there is a ListView and nearby are TextBoxe's . When You Select a row in ListView in TextBoxe's are shown detailed information about this Row, there is a possibility of changing this data. When You change a selection to another row (and data in TextBox'es are changeg by You) I'd like to show a MessageBox with question Accept/Cancel.
Is it more clear now
|
|
|
|
|
Yes, I see now Personally, I would try and avoid lots of "Are you sure?" type pop ups. Especially if it's going to do it every time you select a new item. They can get very annoying for users. I would consider building a databound UserControl for my textboxes then you can update the databound object directly. If you use a DataTable with a DataRow as the databound object you could could use RowState to aid the implementation Accept/Cancel if you wanted.
|
|
|
|
|
Hi, could anyone please help me to upgrade my syntax in c#..
for (int x = 0; x <= DSData.Tables[0].Rows.Count; x++)<br />
{<br />
x1.Text = DSData.Tables[0].Rows[x]["test"].ToString();<br />
}
dataset DS;
foreach (________ in DS)
{
}
??
Dabsukol
|
|
|
|
|
foreach (DataRow row in DS.Tables[0])
{
x1.Text = row["test"].ToString();
}
|
|
|
|
|
shouldn't that be
DS.Tables[0].Rows
??
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Yes... I did that the other day too
|
|
|
|
|
Personally I would not do the "upgrade" in the first place as your code will actually run slower. Unless you have a compelling reason to do so rather do the following:
int rowCount = DSData.Tables[0].Rows.Count;
for (int x = 0; x < rowCount ; x++)
{
x1.Text = DSData.Tables[0].Rows[x]["test"].ToString();
}
|
|
|
|
|
My test says otherwise:
DataTable dt = new DataTable("table1");
DataColumn dc = new DataColumn("col1");
dt.Columns.Add(dc);
for (int i = 1; i < 1000000; i++)
{
DataRow row = dt.NewRow();
row["col1"] = "string" + i.ToString();
dt.Rows.Add(row);
}
long start = DateTime.Now.Ticks;
for (int i = 0; i < dt.Rows.Count; i++)
{
string s = (string)dt.Rows[i]["col1"];
}
long middle = DateTime.Now.Ticks;
foreach (DataRow r in dt.Rows)
{
string s = (string)r["col1"];
}
long end = DateTime.Now.Ticks;
TimeSpan forLength = new TimeSpan(middle - start);
TimeSpan foreachLength = new TimeSpan(end - middle);
Console.WriteLine("for = " + forLength.ToString());
Console.WriteLine("foreach = " + foreachLength.ToString());<pre>
Output:
<code>for = 00:00:00.9079668
foreach = 00:00:00.2661282</code>
But in the scheme of things, less than a second to process 1000000 records, either way fine by me.
|
|
|
|
|
I stand corrected then
I was going according to the MSDN Documentation on enumeration overhead. Thanks for the info.
|
|
|
|