Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于C#桌面应用程序的加载程序动画_C#_.net_Desktop Application_Loader - Fatal编程技术网

基于C#桌面应用程序的加载程序动画

基于C#桌面应用程序的加载程序动画,c#,.net,desktop-application,loader,C#,.net,Desktop Application,Loader,在jqueryajax中是否有类似的方法在C#中发送和完成之前 因为在web中,我通常在按下add按钮时会这样做,我在发送之前设置了一个显示图像和隐藏图像的功能 现在我想在C#桌面应用程序中执行。有类似的吗?就像使用进度条一样,这是winforms应用程序吗?它有一个可供使用的ProgressBar控件。WPF也有一个。但您需要在后台线程上进行处理,以便UI保持响应并更新进度栏。您需要执行后台处理和UI回调。下面是一个非常简单的例子: private void button3_Click(obj

在jqueryajax中是否有类似的方法在C#中发送和完成之前

因为在web中,我通常在按下add按钮时会这样做,我在发送之前设置了一个显示图像和隐藏图像的功能


现在我想在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;
private void按钮3\u单击(对象发送者,事件参数e)
{
ProcessingEvent+=一个事件发生;
ThreadStart ThreadStart=新的ThreadStart(LongRunningProcess);
螺纹=新螺纹(螺纹开始);
thread.Start();
}
私有void LongRunningProcess()
{
提升事件(“启动”);
对于(int i=0;i<10;i++)
{
RaiseEvent(“处理”+i);
睡眠(1000);
}
if(ProcessingEvent!=null)
{
处理事件(“完成”);
}
}
私有void RaiseEvent(字符串whatOccurred)
{
if(ProcessingEvent!=null)
{
处理事件(whatOccurred);
}
}
私有void AnEventOccurred(字符串whatOccurred)
{
if(this.invokererequired)
{
Invoke(新处理(aneventocurred),新对象[]{whatocurred});
}
其他的
{
this.label1.Text=发生了什么;
}
}
委托作废处理(字符串whatOccurred);
事件处理事件;

您需要执行以下操作:

    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(); }
请访问www.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%正确。。。现在在我的系统中工作。

Winforms,如何设置progressbar在函数执行期间运行,以确定它的处理时间或类似的事情。我没有使用WPF。看看API吧,有很多种方法可以做到这一点,这里有一个例子!您想显示的进度是什么?在我的按钮中有一个名为AddProducts()的函数,其中包含sql insert查询。当addProducts()函数完成时,backgroundworker应该从何处开始,并在progressbar中显示进度栏。我将1)重构并将所有产品处理方法放入类/服务中,2)定义这些服务类上的委托和事件,3)创建并启动在UI触发事件(按钮单击等)上执行服务类处理方法的线程;4)在UI类上定义处理事件处理程序。