|
Maybe the StopWatch class can help you.
StopWatch watch = StopWatch.StartNew();
while (watch.ElapsedTicks < someValue)
{
}
somevalue has to be computed from Stopwatch.Frequency to reflect the wanted amount of microseconds. Should be some easy math but I'm too lazy and also want to leave some coding for you
-- modified at 16:26 Monday 14th August, 2006
Just an annotation: This way your thread doesn't really sleep but actively waits for time to go by, so this isn't really good practice and shouldn't be used often.
"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
|
|
|
|
|
It can't be done. The Windows platform doesn't have programmable access to any hardware timers with that kind of resolution.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I was wondering when someone would realise this
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Thread.Sleep(100). This worked for me before
|
|
|
|
|
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
1 millisecond = 1000 microseconds...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Look at the FrameworkTimer in the DirectX SDK!
/\ |_ E X E GG
|
|
|
|
|
Althought the QueryPerformanceCounter function does have a resolution of 1 microsecond, you cannot sleep a process that accurately. The best your going to do is 1 millisecond, and even then, the resolution can vary by 10-15 milliseconds due to Windows being a shared system.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
This may seem general but it has happened quite a few times in my month of using C# in Visual Studio.
There are cases where it is obvious that an exception should be thrown, but instead, the program just hangs there and does nothing.
Ex. double[] a = new double[table.Count];
if table is null, it should throw a NullReferenceException. Instead, the program stops and appears to wait indefinitely.
If this phenomenon is common then I hope someone can explain it to me. If not, then please tell me if you have no idea what I'm talking about.
Thanks,
Stanislav
|
|
|
|
|
tachobg wrote:
If this phenomenon is common then I hope someone can explain it to me. I
This is not common. Is Visual Studio hanging or your entire program hanging?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: And in this corner, the Party of Allah
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
No, it's just the program that hangs.
|
|
|
|
|
You could always check to see if the table is null first. Also, is this code inside of a thread or overridden message?
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Yes, you can definitely prevent such exceptions from happening, but when they do happen, they are pretty hard to debug, since it doesn't give you anything to work with -- you don't know the line number or the type of exception.
As for the second question, no it's not.
|
|
|
|
|
What happens when you wrap it in an immediate try catch?
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
It never gets to the catch part...it tries to execute the statement, then it hangs. Really weird.
|
|
|
|
|
What does the following do:
try{
int index = table.Count;
double[] a = new double[index];
}
catch(Exception e1){
...
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Now it throws an exception. Though it seems strange that no exception is thrown just because you have an embedded statement instead of an assignment. I will do some testing to see if this happens in general or just in my program.
Thanks to everyone for their help.
|
|
|
|
|
As I expected it does exactly as it should outside the context of my program
|
|
|
|
|
Hi,
I was wondering if I could open a MainMenu menu via code?
.NET 1.1
Thanks,
Ron
-- modified at 14:14 Monday 14th August, 2006
|
|
|
|
|
Hi,
I have a process called from a main application, which invokes another 3rd party excutable program having its own UI. The main application has to wait untill the process finishs. My code is:
<br />
process1.StartInfo.FileName = exeFile;<br />
process1.StartInfo.Arguments = argFile;<br />
process1.Start();<br />
process1.WaitForExit();<br />
I hope the 3rd party program will run as a model dialog, but when it's running, the background main application UI can't be seen. Any way to refresh the main application so that user can see its UI when running 3rd party program?
Thanks.
-- modified at 16:12 Thursday 17th August, 2006
|
|
|
|
|
First, place the code above into its own thread. When WaitForExit returns, use Control.Invoke to send a message back to the UI thread. To stop the user from being able to interact with the application, set the form's Enabled property to false , then set it to true when the third-party program exits.
|
|
|
|
|
Hi Mike,
Thanks for your reply. I'm still not sure where to use Control.Invoke. Here is my code:
<br />
private void mainFrameButton_Click(object sender, EventArgs e)<br />
{<br />
ThreadStart worker = new ThreadStart(WorkerThreadMethod);<br />
Thread t = new Thread(worker);<br />
t.Start();<br />
<br />
this.Invoke(worker);<br />
this.Enabled = false;<br />
}<br />
<br />
public void WorkerThreadMethod()<br />
{ <br />
this.process1.StartInfo.FileName = ExeFile;<br />
this.process1.StartInfo.Arguments = ArgFile;<br />
this.process1.Start();<br />
this.process1.WaitForExit();<br />
}<br />
<br />
private void process1_Exited(object sender, EventArgs e)<br />
{<br />
this.Enabled = true;<br />
}<br />
It didn't work, and the worse thing is the third-party program poped up twice, and even it's closed, the main application UI was still disabled.
Some help please? Thanks.
|
|
|
|
|
i use list view that have control in this page
http://www.codeproject.com/cs/miscctrl/ListViewEmbeddedControls.asp
* if i have database with 3 recode ex:
------
field 1
------
5
7
8
-----
i want to add 3 row in the listView with first colum must be button(ClickMe)
the problem new
-----------------
1 - how i make my app when i click in the fisrt (ClickMe) button -> open new Form with 5 as parameter - > new Form(5);
and second button new Form(7);
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
enum MyTemp
{
cold = 0,
fp = 32
}
day1Miles.Text = textBox1.Text;
}
I get an error on 2 ( error says: } expected )
What am I missing in the concepts here? Why can't I define an enumerated constant at top of the button click? I can replace the enum statement with something like int cold = 0; and it works fine, so why can't I put an enum statement here?
For example this compiles without error:
private void button1_Click(object sender, EventArgs e)
{
int cold = 0;
day1Miles.Text = textBox1.Text;
}
-- modified at 12:49 Monday 14th August, 2006
|
|
|
|
|
Try defining the enum outside of your function.
|
|
|
|