HI, In C# how do you compare 2 struct's? Thanks, Liam
LiamD
Posts
-
How to compare struct -
Show Form from (non-GUI) ThreadI was concerned because i have never seen any examples of projects creating a thread for each form. Can you please give an example of code for this? Something liek this ... Form f = new Form(); t = new Thread(new ThreadStart(f)); t.Start(); I just want to make sure that I will not run into problem using this method when running in a multi threaded project. By the way I meant to write Form.Show() method above. Thanks, Liam
-
Show Form from (non-GUI) ThreadI have a thread (which is not the main GUI thread )that I want to be able to create a form using the Show method. The thread basically loops for commands and responds to them. Some of the commands are to display a form - and then wait for the next command. Now when I try to do this the Form freezes i.e. not responding. Now I assume that is because the thread is blocking waiting (Monitor.Wait) for the next command. I suppose this blocking prevent the GUI from responding to events. So my question is related to this problem. 1. Is is good practice to create Form from a thread other than the main GUI 2. Can I do a for.Show method and spawn it into a worker thread? All thoughts and suggestions would be appreciated.
-
Bitfield access to arrayI have an fixed length array :- Byte[] myArray = new Byte[50]; Now this represents a specific message structure. For example, the sort of thing I want to do is : 1. to read and set a bit field, Byte[25], bit 1 2. to read and set a 5 bit value, Byte[20], bits 0-5 3. to read and set a 32 bit number, Byte[10] These are just a few examples of what functions I want to perform on the array. But they highlight some of my challanges. Any thoughts on gneral ways to achieve this? Thanks, Liam
-
Static Members derived from Interface ClassI have a program that consists of a number of messages type. I am trying to ensure that all messages of a given type have a dedicated handler. Each message type has its own message handler. I have created an interface base class which states all messages need a handler. Each derived class should have a single event handler, therefore I used the static keyword so that it is common across all the derived classes i.e. a single handleMsg for all instances of the msg1 class. So I implemented this: interface baseMsg { void handleMsg (); } class msg1 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg1 Handled"); } } class msg2 : baseMsg { … public static void handleMsg () { Console.WriteLine ("msg2 Handled"); } } I am getting an error CS0536: Error Message 'class' does not implement interface member 'interface member'. 'class member' is static, not public, or has the wrong return type So I cannot implement it in the way I originally thought. Does anyone have any suggestion on how I can achieve this? Thanks, LiamD
-
"Safely Remove Hardware" USB Key?Is there a way within C# and .NET Framework to duplicate the "Safely Remove Hardware" functionality. I am using a USB Flash drive on a Windows XP system. I want to be be able to ensure that the device is removed from the system without loss of data. So I would imagine that the would some driver uninstall or removal of the device from registry or other location. Does anyone know of code to achieve this? I am currently using code to raise an event when the USB Flash device is added or removed. Based on the following: http://www.experts-exchange.com/Programming/Programming\_Languages/Dot\_Net/VB\_DOT\_NET/Q\_21599899.html Just to clarify, I cannot use the standard "Safely Remove Hardare" function that appears in the status bar as My application will not boot to the standard windows shell - so there will be no status bar.
-
ISO 8601 Date/Time FormatI know that you can get ISO 8601 date/time format using DateTimeFormatInfo.SortableDateTimePattern. From the VS help on DateTimeFormatInfo.SortableDateTimePattern we can get:- "This code produces the following output. CULTURE PROPERTY VALUE en-US yyyy'-'MM'-'dd'T'HH':'mm':'ss ja-JP yyyy'-'MM'-'dd'T'HH':'mm':'ss fr-FR yyyy'-'MM'-'dd'T'HH':'mm':'ss" However, there does not seem to be any mention of the timezone extension. i.e. in the format YYYY-MM-DDThh:mm:ss±hh:mm How can I add the ±hh:mm based on the current timezone location. Thanks, Liam
-
Queued TimersDave, sorry for the mixed up information I think I am confusing myself too. What I have found is both timers:- System.Threading.Timer System.Timers.Timer Will queue and "handler code" if it cannot be processed immediately. the "handler code" will then be processed when CPU time is avaliable. Whereas System.Windows.Forms.Timer Does not queue and the "handler code" is essentially lost. So I my question applies to both System.Threading.Timer System.Timers.Timer Can I find out if there is a queue of "handlers" (either a callback delegate or an event handler) waiting to be processed?
-
Queued TimersOK my terminology may be wrong. I use the following so I use the the wording "event handler" tmrTimersTimer.Elapsed += new ElapsedEventHandler(tmrTimersTimerElapsedHandler); No each tick does not get it's own thread. The callback code takes about 1-2 ms so should complete in plenty of time. Now if another thread has the processor when my timer elapses it will queue. It will continue to queue timer callbacks. When my code gets the CPU back it will empty the queue and execute all the callbacks. What I was hoping to achieve was to interrogate the queue that holds the timer callbacks.
-
Queued TimersI am using the System.Threading.Timer timer. Now if I have a interval set quite low say 10ms it is possible for my timer event handler to be queued as they cannot be prcessed because the UI thread is busy or another application is running. When the UI thread becomes free it then processes all the queued events at the same time. Is it possible to determine programmatically the number of timer event handlers that are being queued. I want to be able to determine when there is a build up of queued event handlers. Some code to demonstrate this would be useful. Also, is it possible to limit the number of timer event handlers that are queued? Thanks, Liam
-
Queued TimersI am using the System.Threading.Timer timer. Now if I have a interval set quite low say 10ms it is possible for my timer event handler to be queued as they cannot be prcessed because the UI thread is busy or another application is running. When the UI thread becomes free it then processes all the queued events at the same time. Is it possible to determine programmatically the number of timer event handlers that are being queued. I want to be able to determine when there is a build up of queued event handlers. Some code to demonstrate this would be useful. Also, is it possible to limit the number of timer event handlers that are queued? Thanks, Liam
-
Control to Fill Dialog?Khan++, thanks for the reply this worked for a while now it is failing an assertion: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\src\mfc\winocc.cpp void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint) { ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL)); ... Can you explain why this is? Also I would like to be able to have a fixed offset from a border. Can this be done easily. Thanks
-
Tool to detect boxing/unboxing?Does anyone know of a tool (preferably free) to determine the location of boxing/unboxing within a project. The aim is to improve performance and justify all boxing operations. Thanks LiamD
-
Control to Fill Dialog?Hi, I am moving from C# to VC++ to test to see if it will meet my timing requirements. I am not familiar with VC++. I want to add an ActiveX control that fills a dialog box. So the size of the control will always match the size of the dialog when it is resized. This is easily done in C# .NET using the Anchor property. How can I do this in VC++? Can it be done by setting properties or do I have to create extra code to achive this? By the way I am using Visual Studio 2003 to create my code for an MFC application. Thanks, Liam
-
Accessing Form Data from another formI have a main dialog. I then create many new dialog forms which the user interacts with to enter values. I want to be able to retrieve the values that the user enters. I am wondering the best way to design my system to allow access to the values entered by the user in the dialog forms. In my main form, I could add a public access to the dialog form instance. This seems inefficiant and seems to need a lot of effort to maintian. Or perhaps I could update some central class with the entered values. Then I would access that class to retrieve the values. I am sure this is a common thing that has to be done. Does anyone have suggestion as to the best way to achieve this? Thanks, Liam
-
Create 2 forms from button pressMy exact situation is:- Form1 is created from a button press on the main form. Form2 is created on a timer event. When the timer elapes form1 may or may not be present. If not it should be created. If it is form2 is displayed. But Form2 must always be at the top and main form always at the bottom. If I use modeless formas and select the main form then form1 and form2 are hidden - not what I want. Thanks, Liam
-
Create 2 forms from button pressOk I can see how Show instead of ShowDialog might work but I will add extra requirements. Perhaps my requirements are that I want to ensure that frm1 is always above the main form. And also frm2 is always above frm1. Even if the main display is selected I do not want frm1 and frm2 to be lost behind the main form. With a modal form this is the case but if it is modeless form then it looses that feature. How do I get around it. I know this sounds silly but can I have a modal form that itseld creates a modal form? i.e. frm1 is modal based on the main form, and also frm2 is modal based on frm2? Thanks, Liam
-
Create 2 forms from button pressI want to be able to create 2 forms when I press a button. I am using the following code. { frmMy1 frm1 = new frmMy1(); frmMy2 frm2 = new frmMy2(); frm1.ShowDialog(this); frm2.ShowDialog(this); frm1.Dispose(); frm1.Dispose(); } When I run this I have to close the first form before the second form is displayed. Is there any way to get them both up at the same time. Thanks Liam
-
USB Flash Drive or CF accessWhen I boot I will boot directly to my application and bypass the standard windows environment. There will be no task bar available to the user. So I have to mimic what is done in the task bar in a programmatic way within the C# code. Thanks, Liam
-
USB Flash Drive or CF accessIs is possible to access a USB Flash drive / disk from the .NET framework. I want to be able to detect when a Flash drive has been inserted, write to a CF and then allow the user to safely remove it. Will .NET 2.0 have this capability? Thanks, Liam