如何在应用程序的后台线程中运行复杂的功能? [英] how to run a complex function in the background thread of an application?
本文介绍了如何在应用程序的后台线程中运行复杂的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好.
在单击按钮时,我需要运行一个非常复杂的自动滚动系统.原因是我需要能够与表单上的其他流程进行交互.并停止当前的一个这是需要在后台线程中的代码:
hello.
on a button click, i need to run a very complex automatic scrolling system. the reason for this is that i need to be able to interact with other processes on the form. and also stop the current one. here is the code that needs to be in the background thread:
void scroll(IntPtr handle, int pixels)
{
{
IntPtr ptrLparam = new IntPtr(0);
IntPtr ptrWparam;
SCROLLINFO si = new SCROLLINFO();
si.cbSize = (uint)Marshal.SizeOf(si);
si.fMask = (uint)ScrollInfoMask.SIF_ALL;
GetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref si);
telep.DeselectAll();
if (t.Enabled)
{
if (si.nPos < (si.nMax - si.nPage))
si.nPos += pixels;
else
{
ptrWparam = new IntPtr(SB_ENDSCROLL);
t.Enabled = false;
SendMessage(handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
}
if (t.Enabled == false)
{
if (si.nPos > (si.nMin))
si.nPos -= pixels;
else
{
ptrWparam = new IntPtr(SB_ENDSCROLL);
t.Enabled = true;
SendMessage(handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
}
SetScrollInfo(handle, (int)ScrollBarDirection.SB_VERT, ref si, true);
// Send a WM_VSCROLL scroll message using SB_THUMBTRACK as wParam
// SB_THUMBTRACK: low-order word of wParam, si.nPos high-order word of wParam
ptrWparam = new IntPtr(SB_THUMBTRACK + 0x10000 * si.nPos);
SendMessage(handle, WM_VSCROLL, ptrWparam, ptrLparam);
}
}
推荐答案
那么,您的问题是什么?
如果需要传递参数时如何使用BackgroundWorker,请参见此处:
http://tinyurl.com/47hrlqe [ ^ ]
So, what is your question?
If it''s how do you use a BackgroundWorker when you need to be able to pass arguments to it, see here:
http://tinyurl.com/47hrlqe[^]
这篇关于如何在应用程序的后台线程中运行复杂的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文