English 中文(简体)
我如何展示像“载荷”这样的东西,而我对形式负荷做了一些检查?
原标题:How do I display something like "loading.." while I do some checks on form load?

我对形式负荷做了一些检查,但正在锁定表格(约千秒)。 为此原因,我要发表“发送申请”等信息,但我不知道我如何这样做。 我希望这清楚! 任何帮助都受到高度赞赏。 提前感谢。

最佳回答

理想的情况是,你想要做的是,对背景线索进行检查,以便防止天线。 查阅BackgroundWorker 班级。

You should hook your checks to the DoWork event of the background worker, and call the BackgroundWorker s RunWorkerAsync() method from the Form_Load event to kick off the background work.

与此类似(注:未经测试):

BackgroundWorker bw = new BackgroundWorker();
public void Form_Load(Object sender, EventArgs e) {
    // Show the loading label before we start working...
    loadingLabel.Show();
    bw.DoWork += (s, e) => {
       // Do your checks here
    }
    bw.RunWorkerCompleted += (s, e) => { 
       // Hide the loading label when we are done...
       this.Invoke(new Action(() => { loadingLabel.Visible = false; })); 
    };
    bw.RunWorkerAsync();
}
问题回答

你可以创造另一个线,显示装货信息。

首先,你们需要一个包裹。

bool loading = true;

• read:

Thread myThread = new Thread(new ThreadStart(Loading));
myThread .Start();

然后有办法:

private void Loading()
{
    while(loading)
    {
        //Display loading message here.
    }
}

当你装上哪怕是一只装上伪造的装饰时,read子就会终止。

查阅BackgroundWorker。 你们完全需要知识。

可以通过在另一条路面展示单独执行的形式,轻易做到这一点。 以这种形式(指针筒)你可以投放ated或静态案文。 你们所需要的法典如下:

在该类别之后公布一些变量。

public partial class frmMain : Form
{
   public Thread th1;
   static frmSplash splash;
   const int kSplashUpdateInterval_ms = 1;

// Rest of code omitted

然后在你的主要形式上添加以下方法。 这首先进行切片检查:

static public void StartSplash()
{
    // Instance a splash form given the image names
    splash = new frmSplash(kSplashUpdateInterval_ms);

    // Run the form
    Application.Run(splash);
} 

其次,你需要一种办法,以关闭鞭子:

private void CloseSplash()
{
    if (splash == null)
        return;

    // Shut down the splash screen
    splash.Invoke(new EventHandler(splash.KillMe));
    splash.Dispose();
    splash = null;
} 

然后,在你的主要表格Lad中:

private void frmMain_Load(object sender, EventArgs e)
{
    try
    {
        Thread splashThread = new Thread(new ThreadStart(StartSplash));
        splashThread.Start();

        // Set the main form invisible so that only the splash form shows
        this.Visible = false;

        // Perform all long running work here. Loading of grids, checks etc.
        BindSalesPerson();
        BindCustomer();
        BindBrand();

        // Set the main form visible again
        this.Visible = true;
    }
    catch (Exception ex)
    {
        // Do some exception handling here
    }
    finally
    {
        // After all is done, close your splash. Put it here, so that if your code throws an exception, the finally will close the splash form
        CloseSplash();
    }

} 

之后,如果主要形式已经关闭,则确保关闭你间谍屏幕:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
    // Make sure the splash screen is closed
    CloseSplash();
    base.OnClosing(e);
} 

The Code for the Splash form (In frm Splash.cs) is as follows:

public partial class frmSplash : Form
{

    System.Threading.Timer splashTimer = null;
    int curAnimCell = 0;
    int numUpdates = 0;
    int timerInterval_ms = 0;

    public frmSplash(int timerInterval)
    {
        timerInterval_ms = timerInterval;

        InitializeComponent();
    } 


    private void frmSplash_Load(object sender, EventArgs e)
    {
        this.Text = "";
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.ControlBox = false;
        this.FormBorderStyle = FormBorderStyle.None;
        this.Menu = null;
    } 

    public int GetUpMilliseconds()
    {
        return numUpdates * timerInterval_ms;
    }

    public void KillMe(object o, EventArgs e)
    {
        //splashTimer.Dispose();

        this.Close();
    }        
}

我希望这能帮助你。 它可能不是有史以来最好的法典,而是为我工作。

你们需要创造一种在座卸载的形式。 你们需要创建这种形式的目标,并使用读写的概念。 而在Frmloading,它树立了一种形象。

FrmLoading f2 = new FrmLoading();
using (new PleaseWait(this.Location, () =>MethodWithParameter())) {      f2.Show(this); }
f2.Close();

As shown above code you need to create PleaseWait class.

请Wait.c

public class PleaseWait : IDisposable
{
private FrmLoading mSplash;
private Point mLocation;

public PleaseWait(Point location, System.Action methodWithParameters)
{
    mLocation = location;
    Thread t = new Thread(new ThreadStart(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);
}
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签