|
I need to create a program that can simultaneously turn on up to 4 timers that do not control events, but simply record time down to at least a hundredth of a second. This timer must be visibly updated every hundredth of a second on a form to inform the user of the duration of the processes the program is performing. Is there a way to do this in C#? I looked into the Timer control, but can't figure out how to make it work for this purpose.
|
|
|
|
|
Use the Interval property of Timer control to set the time interval after which you want to initiate some action. For example:
Timer.Interval = 10;
Then use the Tick event of the Timer control, which will then fire after every time interval set by you as above. In the event-handler of Tick event, use code to update time in the window as per your requirements.
For example, override the OnPaint method of your window or control where you want to show time and use Graphics methods (Pen , Brush , etc.) to show the actual time. Then in afore-mentioned Tick event-handler, simply use a command like this.Refresh() to refresh the window which will call the OnPaint method to draw / show the updated time after every time interval set by you.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
Contrary to what Ashok told you, DON'T use the Timer control. It's resolution is not guaranteed below 15 milliseconds.
You have a couple of problems...
First, are you going to be able to repaint your data every 10 milliseconds AND monitor your process? Not likely. Repainting is slow...
Second, To get the time resolution you want, you really need to use a high resolution timer that is accessed through the QueryPerformanceCounter API. Search the articles for "high resolution timer" and you'll find a bunch of examples and class libraries demonstrating this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a plug in object that i use in my application
I have 2 interfaces for plugins
IPlugIn
{
}
IMyCompaniesPlugIn:IPlugIn
{
}
when I load a plugin (via Reflection) i want to check whether it is of type IMyCompaniesPlugIn so i can do different stuff for 'known' Plugins
how do i do this test? I can test for any amount of inheritance, but i don't seem to be able to do the same for implementation
Thanks
Russ
|
|
|
|
|
|
thanks
if (myType.GetInterface("MyInterface") != null)
{
}
works perfectly, thanks
Russ
|
|
|
|
|
How can I detect which threads are running inside the application?
I need to know this so I can make a work-around for a deadlocking threads.
I don't have any sourcecode whatsoever of the component I am using, and ofcourse: That component is causing the deadlock. Is there any way I can find the threads it's using and kill those before I quit the application?
WM.
What about weapons of mass-construction?
|
|
|
|
|
Solving deadlocks is not a simple situation especially when details are sparse. The best advice I can give is whenever you are dealing with a 3rd party component not under your control that you suspect is not thread safe, you will need to isolate it in your code. This could end up being complex (dependent on the component) or it could be as simple as anytime you access/manipulate the component put a lock around it. Once your application only touches the flakey component in a thread safe manner some of the flakey behavior that leads to deadlock should go away.
I am hesistent to mention this but if you want a list of threads for a given process, look in the System.Diagnostics.Process object. There is a member Threads which should give a ProcessThreadCollection which you can enumerate over.
|
|
|
|
|
In this case it's a user interface component, that is being used very often. But I think I solved the problem, by calling Application.ExitThread() these somehow kills the threads of the flakey component during shutdown.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Hi,
I have a class where i'm creating a ButtonArray. Once i have created some elements in this array i want to access each of them in order to move them around in a panel. However i can't seem to get the information from the Move() funtion to be used in the MouseUpHandler which is the one handling the release of a button press (dropping the button at a new location).
Could anyone please help me out here, and please do say if you need more code than i have provided.
public void MouseUpHandler(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Move((System.Windows.Forms.Button) sender).Tag), host, _iXCoorRelative, _iYCoorRelative);
}
public void Move(object sender, System.Windows.Forms.Control host, int _iXCoorRelative, int _iYCoorRelative)
{
ButtonArray btnArray = new ButtonArray(host);
btnArray[Convert.ToInt32(((System.Windows.Forms.Button) sender).Tag)].Location = new System.Drawing.Point (_iXCoorRelative, _iYCoorRelative);
}
|
|
|
|
|
Why does it "seem" like you can't get the information? What happens?
Where do you declare the host, _iXCoorRelative and _iYCoorRelaive variables, and where do you specify the values for them?
You send the contents of the Tag object of the button as sender to the Move method, then you reference the contents as a Button object. Do you really store a reference to a button in the Tag object of the button?
---
b { font-weight: normal; }
|
|
|
|
|
How it is possible to load and read .gif, .jpg, .bmp, .png, .mpeg and other files can i open and read in my application divx files?
Is there a free loader dll or similar?
|
|
|
|
|
how to create the COM and COM+ Program in c#
m mohamad rafi
|
|
|
|
|
You Can Create COM+ Application in .Net By Create your dll
and inherit your class from ServicedComponent
and assign Your assembly and each of its classes with distinct GUID values by using the Guid attribute if you don't give it guide value it in the following assembly registeration will assign one for each element But as you now Com+ undersatnd COM not .Net Component so to let other COM Client Find and Use your component you need to register your .Net Component as COM Server in Windows Registry This process called Asssembly Registration
1-sign a .NET assembly using the Strong Name tool (sn.exe).
2-Register your assembly You can do it by more than one way for example in your Project Properties change Register for COM Interop option to true or Use the Assembly Registration tool regasm.exe
for more info look at
Creating COM+ Objects using EnterpriseServices in .NET
[^]
COM/COM+[^]
ServicedComponent Class[^]
To Export your Component As COM Type Libraries You Can use the tools mentioned above but notice that you don not have to inhiret from ServicedComponent ie
1-Create Your Component
2-Export it as Type Lib By Using one of the following tools
*-In Project Properties Set Register for COM Interop option to true
*- Use the Assembly Registration tool (regasm.exe ) with its /tlb option
*-Use the Type Library Exporter tool (tlbexp.exe )
MCAD
-- modified at 14:52 Thursday 29th September, 2005
|
|
|
|
|
Hi All
I want to create an application that is connect to a mobile phone and retrieve some info from it like SMSs , MMSs,etc....
How can I extablish a connection to the phone and start retrieving data;
Thanks
|
|
|
|
|
hi
i have started one thread. it has read four lines. After that i want to wait that thread so that second thread so that execute.
HOw can i wait a particular thread.
i do not to use Thread.sleep(500); it stops all the thread.
I want to wait that thread for some time or tilll other threads completed its job.
thanks
|
|
|
|
|
Thread.Sleep will only cause the thread on which you called it to sleep, it won't affect other threads. If you have specific places in code where you want to wait/notify, you can use the AutoResetEvent[^] class. Something like
class Test
{
AutoResetEvent evt = new AutoResetEvent(false);
void Thread1()
{
evt.WaitOne();
}
void Thread2()
{
evt.Set();
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi all,
I have an exe which i want to register as windows service programatically in a C# project. This exe is in a folder on the system.
Any help on this........
Lata Agrawal
|
|
|
|
|
have you tried srvany.exe
i think it's available from MS or on the resource kits
If you actually want to modify the source code for your exe, there are a few articles on the web that deal with this, there are problems with debugging a service though, although work arounds are available.
Russ
|
|
|
|
|
hi,when we speek in Microphone (during chatting)some binary data is stored in the RAM.can any one tell me the way through which i can access those bytes. i will be very thankful to u.
|
|
|
|
|
i have an mdi form containing a child form. When a button is clicked, a child form is shown. When the same button is clicked again, a new instance of the same form then appears again --> 2 of the same form appear at the same time. Is there any way that i can check for the child form's existence and show it if an instance of its is already generated?
Thank you so much.
KiT
-- modified at 8:53 Thursday 29th September, 2005
By the way, here's my code:
private frmMcStock mcStock;
private void tscmdMcStock_Click(object sender, EventArgs e)
{
if (mcStock == null)
{
mcStock = new frmMcStock();
mcStock.MdiParent = this;
mcStock.Show();
}
else
{
mcStock.Focus();
}
}
-- modified at 9:03 Thursday 29th September, 2005
|
|
|
|
|
You can simply have a class member variable where you store the instance of the child form. Next time you click the button, check if the variable is null. Something like
class MainForm
{
Form childForm;
public void CreateForm()
{
if (childForm == null)
childForm = new ChildForm();
else
childForm.Focus();
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
OH... How could i forget about .Focus() Must be 'cuz of the flu. I kept trying to use .Show() instead and nothing happened. Thank you so much...
KiT
-- modified at 8:49 Thursday 29th September, 2005
Another problem occured. When i close the opened child form, i cannot re-open it by clicking the same button. It seems like the child form is not disposed. Here's my code:
private frmMcStock mcStock;
private void tscmdMcStock_Click(object sender, EventArgs e)
{
if (mcStock == null)
{
mcStock = new frmMcStock();
mcStock.MdiParent = this;
mcStock.Show();
}
else
{
mcStock.Focus();
}
}
|
|
|
|
|
Hi
I need to convert a ushort[] to byte[].
if this was C I wouldn't be asking but I wonder how to do this most efficient (new array + for) in C#
Gilad.
Ofcource the other way around is a must...
|
|
|
|
|
Try the Array.Copy method:
byte[] newArray = new byte[original.Length];
Array.Copy(original, newArray, original.Length);
---
b { font-weight: normal; }
|
|
|
|