const int WAIT_OBJECT_0 = 0;
const int QS_ALLINPUT = 255;
const int INFINITE = -1; //自定义数据类型
struct LARGE_INTEGER
{
public long QuadPart; }
[DllImport("kernel32.dll")]
static extern bool SetWaitableTimer(int hTimer,
LARGE_INTEGER pDueTime,
int lPeriod,
int pfnCompletionRoutine,
int lpArgToCompletionRoutine,
bool fResume);
[DllImport("kernel32.dll")]
static extern int CreateWaitableTimerA(int lpTimerAttributes,
bool bManualReset,
int lpTimerName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CloseHandle(int hObject); [DllImport("user32.dll")]
static extern int MsgWaitForMultipleObjects(int nCount, int pHandles,
bool bWaitAll, int dwMilliseconds, int dwWakeMask);
//调用时SetWaitableTimer 那里开始出错...程序的作用是一个精确到毫秒的等待.不知不用API,C#里是否有自己带的涵数
public void gjdwait(int weimiao)
{
int hTimer;
LARGE_INTEGER int65=new LARGE_INTEGER ();
int65.QuadPart = -10 * weimiao;
hTimer =CreateWaitableTimerA (0,false ,0);
SetWaitableTimer(hTimer, int65, 0, 0, 0, false);
while (MsgWaitForMultipleObjects(1, hTimer, false, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
{
Application.DoEvents();
}
CloseHandle(hTimer); }
解决方案 »
- DLL调用值C++ 对应的C#的问题
- 为什么走到new的时候就跳出来了啊?
- c#注册码怎么做
- 多个checkbox赋值,急
- 如何给数组赋值
- 关于异常的提示
- 怎样在ListView控件中显示每个文件自带的图标?
- 取三天以前的时间及取一个星期以前的时间及一个月以前的时间及一年以前的时间怎么用C#中的DateTime这个类中所提供的方法和属性实现,或
- C# winform 报表预览双击有子报表的地方 如何禁止弹出新窗口
- Bitmap.save 的问题。
- 那位兄弟有ASP(C#).NET+SQL SERVER 2000的三层结构的OA,给小弟来一份.谢谢了!!!!!!!!!
- DataTable中怎样将多行移到指定的位置,超急!
不要什么都去用WinAPI
Thread thread1 = new Thread(new ThreadStart(方法名))
指定执行你要进行的操作(方法),不要带参数然后再开一个 Timer 控件,设置 Timer 的 Interval 属性
(毫秒级,隔多少时间执行一次 Tick 方法)
定义好 Timer 的 Tick 方法(比如检查分支线程的执行状况啦,显示百分比啊)最后 thread1.Start()
Timer.Start()
OK。