|
Eggie,
You need to read about the Thread.Sleep method and more importantly what a context switch is.
Sleep( X ) means the thread will not be scheduled for execution by the operating system for X milliseconds. Sleep(0) causes the thread to be suspended (a context switch) and immediately rescheduled for another time slice. If there are no other threads at your thread’s priority level then it is executed.
The bottom line is you will not be able to create a delay to the precision you are looking for. (Well, you might be able to with in-line assembly but a context switch could occur and make the “delay” longer. And, now that I think about it, you will probably have to boost your thread’s priority. ) Sleep(0) is the shortest delay that I can think of but there is no control over its duration. Since there will be other threads waiting, they will all execute their time slices before yours gets the CPU back. I don’t recall what Microsoft has a time slice set at its probably around 50ms so if there are n threads scheduled before yours the delay will be n * ~50ms
In the post above Daniel wrote “More time resolution is only available with multimedia timers or DirectX.” He is right. What I’m speaking about is similar to you listening to music or watching a dvd on your computer. If you do anything that uses the CPU a lot, the music or movie becomes "choppy." That is, indirectly, related to the context switches that I’m talking about. Besides these context switches there are other things like interrupts going on(e.g. moving the mouse).
Anyway, there is always a workaround for coding problems.
Good luck.
BTW: You got me curious. Why do you need such a short delay for?
Context switch:
(this is just a summary, Google around for more details)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/context_switches.asp
Sleep Method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadclasssleeptopic1.asp
|
|
|
|
|
I'm making a program... well I have a program that sends data though the parallel port and stores it in the memory on my board...
The data is just a 50,000 line .xml file with a bunch of Hexidecmial.
Everything works fine... except I need that delay between bytes to be more precise...
I just downloaded the DirectX SDK, now I have to figure that out...
uh... anymore suggestions?
/\ |_ E X E GG
|
|
|
|
|
why not do a delay like the old way we'd do it in DOS?
DoProcess()<br />
DoProcess()<br />
DelayCode()<br />
DoProcess()<br />
<br />
<br />
<br />
public void DelayCode()<br />
{<br />
for (int i=0; 1<1000; i++)<br />
continue;<br />
}
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Maybe Thread.SpinWait could help you.
More time resolution is only available with multimedia timers or DirectX.
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
Can it sleep from 1 micro second?
/\ |_ E X E GG
|
|
|
|
|
|
I have a simple console app I created in C#.net. Can I just distribute the exe ?
We use to be able to this ..
When I give it to some people it says "NTVDM CPU has encountered an illegal instruction". I gave the exe to people running WIN2K and WINXP. Do I need to distribute files with a console app. ( yes, they do have .NET 1.1 running on their machine )
It does work on developers machines though ..
ANYONE ??
|
|
|
|
|
Dato wrote:
When I give it to some people it says "NTVDM CPU has encountered an illegal instruction".
I've seen this kind of behavior with some viruses which doesn't understand the format of a .EXE .NET assembly and corrupt it. See if your customer's machines aren't infected.
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
For some reason ..
You can't throw around Console exe anymore. Even if the .NET framwork is on the target machine. I had to create a setup project and it worked fine..
I need to read more on distribution really... I don't understand all the ins/outs...
|
|
|
|
|
This behavior does not have anything to do with .NET framework but with restrictions with the cmd under those machines. Look into:
http://www.derkeiler.com/Mailing-Lists/securityfocus/pen-test/2003-05/0115.html
To bypass these restrictions.
|
|
|
|
|
Thks anonymous ..
Will look into it..
|
|
|
|
|
O.K. this is just out of interest as I've decided to use GDI+ but I was wondering if anyone knows how to double buffer a direct draw window as part of a standard windows application. The problem as I understand it is that for the double buffering to work the device needs to be exclusive which means it needs to be full screen and I've tried and failed to create a back buffer and then draw the data to the back buffer before drawing the back buffer to a primary buffer. Note though that you can't set up the back buffer as a true back buffer because of the exclusive problem so it was set up up as an offscreen surface.
So anyone with any ideas that might just be stupid enough to work?
pseudonym67
Neural Dot Net Articles 1-11 Start Here[^]
|
|
|
|
|
I'm pretty sure that there's an article or two here on CP that shows how to do this (maybe as just a side-light to the real article, though).
John
"We want to be alone when we hear too many words and we feel alone when it has been a while since anyone has spoken to us." Paul David Tripp -- War of Words
|
|
|
|
|
Steps:
1) Create a bitmap the size of the area to be painted.
2) Create a Graphics from the bitmap, using Graphics.FromImage.
3) Use the Graphics object's drawing functions to draw on the bitmap.
4) Use Graphics.DrawImageUnScaled to draw the bitmap onto the screen.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Cheers I'll have a play with that when I get chance. The GDI+ stuff didn't take that long to get working so it's just out of curiosity to see if it works.
pseudonym67
Neural Dot Net Articles 1-11 Start Here[^]
|
|
|
|
|
I've always passed around a reference to an instance of a Logger in most apps that I've developed. There has to be a better way. What do you guys do? I'd like to make a single instance that can be used anywhere in the program. Should I be considering a Singleton design pattern.... ???
I don't need anything fancy. All I need to do is:
MyLogger.Log("Message");
Is it possible to make an instance global to a namespace?
|
|
|
|
|
|
Write a logger class that has a single static method:
public class Logger {
static public Log(string msg);
}
Then you would call the Log method like this:
Logger.Log("Sent a message");
Of course the logger class would have a bunch of private methods and classes underneath to use a logging instance of some type that does the work.
An alternative is to write a classic Singleton.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Inherit a class from System.Diagnostics.TraceListener. On application start, add an instance of this class to the System.Diagnostics.Trace.Listeners and/or System.Diagnostics.Debug.Listeners collections.
Every time you use Trace.Writexxx or Debug.Writexxx, it will be logged through your class. If you change/expand your logging facilities at some time, you don't have to change any client code, just your TraceListener.
|
|
|
|
|
I am launching a cmd prompt via my C# app that runs "net stop mssqlserver /y". This works in Debug mode, but the compiled application opens the cmd window and then closes it immediately without executing the line. Anyone else experienced this?
Attatching debug app exe when solution in debug mode also fails to complete the operation
|
|
|
|
|
|
Also I'm assuming you're using System.Diagnostics.Process.Start instead of ShellExecute, right?
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
This is my code:
-----------------------------------------
Process commandPrompt = new Process();
commandPrompt.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe";
//commandPrompt.StartInfo.Arguments = command;
commandPrompt.StartInfo.UseShellExecute = false;
commandPrompt.StartInfo.RedirectStandardInput = true;
commandPrompt.Start();
commandPrompt.StandardInput.WriteLine(command);
-----------------------------------------
I am trying your suggestions - thanks
|
|
|
|
|
Hello,
Is it possible to easily swap values of primary key column between two rows of one DataTable object? I've been trying it like this;
<br />
DataRow dr1=dt.Rows.Find(5);
DataRow dr2=dt.Rows.Find(10);<br />
dr1.BeginEdit();<br />
dr2.BeginEdit();<br />
dr1["item_Id"]=10;<br />
dr2["item_Id"]=5;<br />
dr1.EndEdit();
dr2.EndEdit();<br />
Same thing happens with dt.AcceptChanges();
Is there a way how to achieve this? Any clues are highly appreciated!
Rado
|
|
|
|
|
DataRow dr1=dt.Rows.Find(5);
DataRow dr2=dt.Rows.Find(10);
dr1.BeginEdit();
dr1["item_Id"]=-1;
dr1.EndEdit();
dr2.BeginEdit();
dr2["item_Id"]=5;
dr2.EndEdit();
dr1.BeginEdit();
dr1["item_Id"]=10;
dr2.EndEdit();
dt.AcceptChanges();
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|