sorry, that's in win form!

解决方案 »

  1.   

    Can you show some of your codes.I use this approach , but my application run well.Is the background thread priority higher than that of the main thread?
      

  2.   

    using System;
    using System.Drawing;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WinApp
    {
    /// <summary>
    /// Summary description for frmTest.
    /// </summary>
    public class frmTest : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    public System.Windows.Forms.PictureBox pictureBox1;
    private System.ComponentModel.Container components = null; public frmTest()
    {
    InitializeComponent();
    } protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } [STAThread]
    public static void Main() 
    { Application.Run(new frmTest()); } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmTest));
    this.button1 = new System.Windows.Forms.Button();
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(32, 224);
    this.button1.Name = "button1";
    this.button1.TabIndex = 2;
    this.button1.Text = "LoopStop";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // pictureBox1
    // 
    this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
    this.pictureBox1.Location = new System.Drawing.Point(32, 24);
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(312, 136);
    this.pictureBox1.TabIndex = 3;
    this.pictureBox1.TabStop = false;
    // 
    // frmTest
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(512, 485);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.pictureBox1,
      this.button1});
    this.Name = "frmTest";
    this.Text = "frmTest";
    this.Load += new System.EventHandler(this.frmTest_Load);
    this.ResumeLayout(false); }
    #endregion private void button1_Click(object sender, System.EventArgs e)
    {
    //模拟后台程序
    double l;
    for(int i=1;i<5;i++)
    {
    for(int j=1;j<30000;j++)
    for(int k=1;k<1000;k++)
    l=(j+k)/(2*j+2*k);
    }
    } }
    }
      

  3.   

    这样的操作最好放到后台线程执行,否则用户界面会暂时停止响应。
    private void button1_Click(object sender, System.EventArgs e)
    {
    ThreadStart ts=new ThreadStart(calculate);
    Thread newThread=new Thread(ts);
    ts.IsBackground=true;
    newThread.Start();
    }
    private void calculate()
    {
    double l;
    for(int i=1;i<5;i++)
    {
    for(int j=1;j<30000;j++)
    for(int k=1;k<1000;k++)
    l=(j+k)/(2*j+2*k);
    }
    }
      

  4.   

    加一个timer,在timer的事件里切换不同的图片就可以了
      

  5.   

    换图片是一种方法(songtongfeng(逸飞) 的方法或者在循环的代码中直接换),可是如果计算时间很长的话,不仅是界面友好性的问题,主要是用户界面在这段时间内会停止响应。微软的文档也建议这样的长时间的操作放到后台线程。
      

  6.   

    按你的说法,用户界面在这段时间内可定是会停止响应。不管用什么方法,不仅不能进行任何输入,而且连显示一幅gif图片都是不行的,是吗?同步真的很麻烦呀,就没有别的办法了吗?