在jquery ajax beforeSend 中是否有类似的方法并在C# 中完成?
因为在网络中,我通常在按下添加按钮时会设置beforendSend:
一个功能来显示图像并隐藏图像功能complete:
现在我想在 C# 桌面应用程序中做。有没有类似的?像某种使用进度条
在jquery ajax beforeSend 中是否有类似的方法并在C# 中完成?
因为在网络中,我通常在按下添加按钮时会设置beforendSend:
一个功能来显示图像并隐藏图像功能complete:
现在我想在 C# 桌面应用程序中做。有没有类似的?像某种使用进度条
这是一个winforms应用程序吗?它有一个可以使用的 ProgressBar 控件。WPF 也有一个。但是您将希望在后台线程上进行处理,以便您的 UI 保持响应并更新您的进度条。
您将需要执行后台处理和 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;
您需要实现如下:
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(); }
请稍等.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% 正确......现在在我的系统中工作。