I'm having troubles trying to get my MainMenu component to display in my C# program. I created my MainMenu object by dragging it from the Windows Form components in the .NET Toolbox onto my main Form. It looks like it is there as it is added in the "#region Windows Form Designer generated code" area. But when I run the program, the menu items do not display and you cannot click on anything. Can someone please help me? Thanks in advance.
McSmack
Posts
-
Troubles Getting the MainMenu Component to display -
Modal Dialog help in C# [modified]Hey Alexander, Hopefully I can answer these questions to the fullest 1) What symptoms cause you to think that the secondary thread is still running? I'm most likely wrong, but it seems to be still running. My main form has a TextBox window that gives me updates of where the data control is at, and my ShowMyDialogBox() displays a transparent modal dialog over the main form. When I place the BeginInvoke(new MethodInvoker( this.ShowMyDialogBox)) line in my ShowMyDialogBox() method as you suggested, the dialog comes up and it is modal, but I can still see that the code is still running, displaying me updates in the main form's TextBox. 2) How is the thread created in the serial library? If you don't know, could you point me to the place on this site that has the serial library so I can check the code? Here are the lines in the library that create the thread.. rcvNotifyThread = new Thread(new ThreadStart(RunRcvNotifyThread)); rcvNotifyThread.Priority = ThreadPriority.Normal; rcvNotifyThread.Name = "Notify " + portName; rcvNotifyThread.Start(); // Start the new thread =========================================================== When you said that the MethodInvoker is just a delegate, it got me thinking. So I played around with it and found a good place to bring the secondary thread back to the main thread. Upon entry of my callback function, I decide to place your solution here since the method that runs all my data processing matches the MethodInvoker delegate. See below public void ReceiveDataFromSerial(); //Just here to show you the prototype // the method that implements the delegated funtionality public void ProcessIncomingData( ) { string testString = "Thread is named: " + System.Threading.Thread.CurrentThread.Name; System.Diagnostics.Trace.WriteLine(testString); Console.WriteLine(testString); //If not in the main thread, move there and let old thread end if(this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(this.ReceiveDataFromSerial)); return; } // Process Data ReceiveDataFromSerial(); // This function process all } This seems to do the trick. I will keep testing it to make sure everything is sound. I truly appreciate all your help Alexander. Regards, McSmack
-
Modal Dialog help in C# [modified]Thanks in advance for all your help. One of the programmers here, created the serial DLL I am using. In that library he has a notify delegate which I subscribe to. His delegate has a couple of parameters which allows me to retrieve the data. Because I deal with a few different communication entities, I created a class which encapsulates the serial DLL, as well as some other specific comm stuff. In my class, I have // Callback delegate that subscribers must implement
public delegate void DataReceivedHandler();
public event DataReceivedHandler OnDataReceived;
where OnDataReceived gets called inside my subscribed function with the serial library. Sorry for the longwinded description. So the answer to one of your questions is that once the library receives data, it creates a "notify" thread and calls my subscribed function which is in my comm class. The code is below private void SerialConnection_PacketReceived(object sender, ReceivedPacket pkt)
{
// If anyone is subscribed to callback, notify them
if( OnDataReceived != null )
{
m_receivedPacket = pkt;
m_dataSizeReadIn = (int)m_receivedPacket.packet.Length;
Buffer.BlockCopy( m_receivedPacket.packet, 0, m_buffer, 0, m_dataSizeReadIn );
// Call Subscriber
OnDataReceived();
}
}
The serial class (which is also a form) is a member of my main form. The ShowDialogBox() resides in my Main Form. But I could easily move it to serial class. What do you think? Regards, McSmack -
Modal Dialog help in C# [modified]Thanks for the tremendous help Alexander! Indeed, my modal dialog was being run in another thread. So after applying your solution it worked, however, my old thread is still running and executing code as well as the new main thread which is executing the same code. I'm not a thread expert. Is there a way to terminate the old thread after the this.BeginInvoke() is called? Thanks again for the help. McSmack
-
Modal Dialog help in C# [modified]I have found a condition where my dialog does not stay modal. I'm using the following snipit of code to create my modal dialog... public void ShowMyDialogBox() { MessageForm testDialog = new MessageForm(); // Show testDialog as a modal dialog and determine if DialogResult = OK. if (testDialog.ShowDialog(this) != DialogResult.OK) { Console.WriteLine("ERROR Broke Modal DialogBox\n"); } testDialog.Dispose(); } This method is called when my serial communications callback function gets called. When the message dialog is displayed, I can still click on the parent form to move it around, or perform button click actions. The only thing I can think of at this point is it might be a threading issue, where the callback is running in a different thread than the main thread. Can anyone help me? McSmack -- modified at 20:59 Wednesday 28th June, 2006
-
Serial CommunicationsHello, I just had a general question about MSComm32 or Serial Communications in .NET. When using binary transmission and receive with RThreshold = 1 (OnComm fired after every byte), does the transmission of binary data act the same as the receive data? Meaning, do I have to place one byte at a time in the MSComm.output field or can I place a whole byte array into MSComm.output? I tried looking for examples, but every sample I found uses text transmission or is in Win32 Native. Any help is much appreciated. Thanks in advance. Mike