有没有一种在jquery ajax beforeSend中类似并在C#中完成的方法?
因为在网页中,我通常会像按下add按钮一样设置beforendSend:
,这是一个在complete:
中显示图像和隐藏图像的函数
现在我要做的是在C#桌面应用程序中。有没有类似的东西?就像使用进度条一样
发布于 2012-11-15 10:44:27
这是winforms应用程序吗?它有一个可以使用的ProgressBar控件。也有一个用于WPF的。但您可能希望在后台线程上进行处理,以便您的UI保持响应并更新您的进度条。
发布于 2012-11-15 11:12:15
您需要执行后台处理和UI回调。下面是一个非常简单的例子:
private void button3_Click(object sender, EventArgs e)
{
ProcessingEvent += AnEventOccurred;
ThreadStart threadStart = new ThreadStart(LongRunningProcess);
Thread thread = new Thread(threadStart);
thread.Start();
}
private void LongRunningProcess()
{
RaiseEvent("Start");
for (int i = 0; i < 10; i++)
{
RaiseEvent("Processing " + i);
Thread.Sleep(1000);
}
if (ProcessingEvent != null)
{
ProcessingEvent("Complete");
}
}
private void RaiseEvent(string whatOccurred)
{
if (ProcessingEvent != null)
{
ProcessingEvent(whatOccurred);
}
}
private void AnEventOccurred(string whatOccurred)
{
if (this.InvokeRequired)
{
this.Invoke(new Processing(AnEventOccurred), new object[] { whatOccurred });
}
else
{
this.label1.Text = whatOccurred;
}
}
delegate void Processing(string whatOccurred);
event Processing ProcessingEvent;
发布于 2016-11-24 17:24:03
您需要实现如下所示:
FrmLoading f2 = new FrmLoading(); // Sample form whose Load event takes a long time
using (new PleaseWait(this.Location, () => Fill("a"))) // Here you can pass method with parameters
{ f2.Show(); }
PleaseWait.cs
public class PleaseWait : IDisposable
{
private FrmLoading mSplash;
//public delegate double PrdMastSearch(string pMastType);
public PleaseWait(Point location, Action methodWithParameters)
{
//mLocation = location;
Thread t = new Thread(workerThread);
t.IsBackground = true;
t.SetApartmentState(ApartmentState.STA);
t.Start();
methodWithParameters();
}
public void Dispose()
{
mSplash.Invoke(new MethodInvoker(stopThread));
}
private void stopThread()
{
mSplash.Close();
}
private void workerThread()
{
mSplash = new FrmLoading(); // Substitute this with your own
mSplash.StartPosition = FormStartPosition.CenterScreen;
//mSplash.Location = mLocation;
mSplash.TopMost = true;
Application.Run(mSplash);
}
}
它的工作100%正确...目前在我的系统中工作。
https://stackoverflow.com/questions/13390778
复制相似问题