|
Can't you use the "Watch" capability of the debugger?
As I recall, you can set a Watch to break when an expression changes, so just make up an expression that evaluates some member of your Queue, and set it to break when that changes.
|
|
|
|
|
See, the problem is that any item in the queue is being changed and arbitrarily. Its also quite tentative. I've narrowed it down to the method that's causing the change, but I'll be damned if I see what the heck is wrong.
|
|
|
|
|
Perhaps logging might be more helpful in this instance.
Create a log file and write to it every time this method is called.
|
|
|
|
|
That is precisely what I did.
|
|
|
|
|
Well, most likely the items are not changing because they are in the queue, which means that you probably have a reference somewhere to some of the items or some of the members of some items. Check what happens from when you create the items until you put them in the queue, to see if you might keep a reference to something or reusing something that you already have a reference to.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I changed it to a queue of strings. Solved the problem, but that's just a hack until I can get back to it and get to the bottom of it. But I have no external references, that's what's driving me insane.
|
|
|
|
|
Well, strings are immutable, so that is consistent with my theory.
I'm not talking about external references, I'm talking about references to the objects that you store in the queue.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
you may want to check what happens to your items after you have put them in the queue too, if
they are reference items the only that gets queued is a pointer, not the actual values...
|
|
|
|
|
how can i simply send data between my main form and a shown user control eg if a usercontrols button is pressed have it send to the main form as if a button was pushed in the main form. or to have a user control edit a string on the main control. seemingly simple stuff but i cannot find any examples.
thanks in advance. Callum
|
|
|
|
|
dustybike wrote: have a user control edit a string on the main control
Child controls should not know about their parent controls. If they do then you can't reuse the control and there would be no point in having it.
A number of possible solutions.
1. Use the observer pattern and have your user control expose an event that the main form handles. Your event is triggered by the button click.
2. Create an interface and have the main form implement it. Pass a reference to the interface (i.e. the form object) to the user control when the form is created. When the button is clicked it can invoke the method on the interface. If you have multiple forms that use the control they will each need to implement the interface.
|
|
|
|
|
The child knowing about the parent is the simplest way though. Make a global variable that points to the parent form, or pass a variable pointing to the parent form into the user control and invoke methods on the parent. There is a point to having user controls in this case, both for code encapsulation/organization, or if the parent needed more than one of these children and each had their own index.
class Form1 : Form
{
public Form1()
{
Form2 form2 = new Form2( this );
}
}
The event way mentioned is a little trickier but not much. Make a public event inside Form2.
public delegate void MyDelegate(object owner, EventArgs args);
public event MyDelegate myEvent;
private void OnEvent(object owner, EventArgs args)
{
object[] argsArray = new object[2];
argsArray[0] = owner;
argsArray[1] = args;
this.BeginInvoke( myEvent, argsArray );
}
Now anyone can subscribe to myEvent and call their own event handler.
Use interfaces if you prefer the abstraction of prgramming to interfaces. Some people consider this the most reusable code.
|
|
|
|
|
Code Soldier wrote: The child knowing about the parent is the simplest way though
It is very bad design and means that the child cannot be used on other forms because it is tied to its original parent form.
Code Soldier wrote: Make a global variable
Oh... Joy! More bad design.
Code Soldier wrote: There is a point to having user controls in this case, both for code encapsulation/organization, or if the parent needed more than one of these children and each had their own index
Okay - buy why shut out the rest of the world in the process.
|
|
|
|
|
Good Afternoon to all
Currently, i'm doing a program that send commands through my serial port via GSM Modem to a remote equipment. After sending the first command, i'm receiving the first packet where it cames the packet counter which value i need to obtain the rest of packets. To do this, i'm writing the first packet on a text file, and then i'm going to search the packet counter value. But there's a problem, after making the GSM connection, i receive the CONNECT string and it is saved into my text file, but after this, when i send the first command, the first received data packet remains in the buffer (byte array), without going to my text file. When i'm reading the file, only the CONNECT string is saved on the file.
I'm sending the functions i'm using to monitor the received data:
private void OnComm(object sender, EventArgs e)
{
int counter = new int();
if (com.InBufferCount > 0)
{
try
{
Stream s = new MemoryStream((byte[])com.Input);
counter = Convert.ToInt32(s.Length);
byte[] fileData = new byte[counter];
s.Read(fileData, 0, counter);
s.Close();
ReadDeviceResponse(fileData);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
private void ReadDeviceResponse(byte[] response)
{
WritePacketDataOnTextFile(response);
for(int i = 0; i < response.Length; i++)
{
rtfTerminal.AppendText(response[i].ToString() + " ");
}
rtfTerminal.AppendText("\n");
}
public static void WritePacketDataOnTextFile(byte[] Buffer)
{
int i;
FileInfo file1 = new FileInfo("C:\\Users\\AJorge\\Desktop\\TestData.txt");
StreamWriter sw = file1.AppendText();
for (i = 0; i < Buffer.Length; i++)
sw.Write("{0} ", Buffer[i]);
sw.Close();
}
Could anyone help me with this?
Best Regards.
|
|
|
|
|
You must call "Flush()" before closing the text file.
|
|
|
|
|
Hi Richard,
I've done what you said earlier but... the problem still remaining. I was thinking that it was some kind of timing problem, but even setting a Thread.Sleep of 1000ms, the buffer still not releasing the data.
Best regards.
|
|
|
|
|
Hi Richard,
Richard Andrew x64 wrote: You must call "Flush()" before closing
IMO that is a common misconception. Close calls flush to force the data out, so you never HAVE to
call it.
The only time you should call flush is when you want to force data out when you want to make
sure the data is output AND you do not intend to close immediately; e.g. when part of the file
has been generated and you expect an exception/crash in the remainder of the code.
|
|
|
|
|
You use the variable named com in OnComm event handler, but it's obviously defined somewhere else (at class level?). I'd guess that it's contents are not refreshed so you maybe getting the old response when a new event arises.
|
|
|
|
|
Hi to all!
The problem is still remaining. I'm going to tell you in a few points, what i'm doing.
The received data monitoring function is buffering the incoming data and when is received, it writes that data into a text file.
When i make the connection with the remote system, i receive the confirmation bytes and then, they're saved into the text file. After this, i'm sending a command to obtain my first packet from remote system and when i receive that packet, i want that to be saved in the same text file, from where i'm going to extract the packet counter to use in the rest of commands.
The problem here is that my program calls the function which is searching that packet counter before the data reaches the text file, and then appears the error: "Index was outside the bounds of the array."
I already tryed to introduce some Thread.Sleep calls, but is not resulting too.
Best Regards.
|
|
|
|
|
Another question,
Is it possible to make the buffer discharge rigth after receiving data without waiting until full message reception?
Best regards
|
|
|
|
|
Hi to all!
The problem is finally solved. A do-while loop with Application.DoEvents() and a FileSystemWatcher Object. In this way, i could monitor changes on the text file, and only when the packet counter was writen on the file, the catch packet counter routine is called.
Best regards.
|
|
|
|
|
Hi, I'm really new to C# so I hope everyone forgives if my question is a silly one. I'm basically a PHP programmer turned C# Programmer for a new project being developed at my office.
Here is what I want to do, I have an application that has some menu items on the top. Now when user clicks on one of the menu item, I want to show the form that contains the interface to be shown in the main form instead of launching a separate form.
I hope I made myself clear. Maybe an example would be helpful. Well here goes.
Example: There is a menu item named "User Management". When someone clicks that menu item the interface would show a list of users, their login details, position etc. Now what I want is that this information will be shown in the form containing the menu, not in a separate form launched when that menu is clicked. Since there are different menu items doing different things, the main form will probably act like a container of some sort that has a designated area where other forms ( or other controls ) can simply show up.
Thanks in advance for any help.
|
|
|
|
|
Instead of making forms, create UserControls, add them to the main form, and show/hide them as needed. For an example of what I mean, check out my wiard form article[^]. In that article, the various wizard pages are nothing more than user controls. For your needs, the forms would change based on the menu item that was clicked.
"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
|
|
|
|
|
Thank you very much. I guess I can use that very well written article of yours as a guide.
|
|
|
|
|
If you want an SDI (single document interface) I would use some of the dynamic controls .NET provides and make the data "fit" into the main form somehow. If your main form had generic space for properties (i.e. a property table), fill the user data into there. All of the controls and layout panels in .NET offer some sort of on the fly data filling or layout changing. Add/Remove controls from parents, or make them invisible to build the UI as needed.
If you want an MDI (multiple document interface), which is little windows contained inside a big one, I would use a 3rd party MDI creator like this one: http://www.arstdesign.com/articles/sdimdiwizards.html[^]
Word is an MDI using many windows for your many documents or views of documents. IE is an SDI, using a tabs user control to show many layouts / documents.
|
|
|
|
|
Thank you for your reply. I guess I will use that app you linked to. Will have to go through a bit of testing to know which will serve me best. Thanks once again.
|
|
|
|