protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "321";
Thread.Sleep(10000);
TextBox1.Text = "123";
}请问如何先执行 TextBox1.Text = "321"; 然后在走线程?
{
TextBox1.Text = "321";
Thread.Sleep(10000);
TextBox1.Text = "123";
}请问如何先执行 TextBox1.Text = "321"; 然后在走线程?
然后申明thread对象。using System.Threading;Thread Thread_InitSys = new Thread(new ThreadStart(InitSystem));
Thread_InitSys.Start();
下面是initSystem函数的申明:private void InitSystem()
{
while(true)
{
//在此添加操作代码
}
}
这样就启动了一个线程。
先申明一个委托和回调函数。 delegate void SetTextBox1(string txt);
private void setTextBox(string txt)
{
if (this.TextBox1.InvokeRequired)
{
SetTextBox1 d = new SetTextBox1(setTextBox);
this.TextBox1.Invoke(d, txt); }
else
{
this.TextBox1.Text = txt;
}
}然后在线程中调用setTextBox函数来改变text属性。
using System.Threading; Thread Thread_InitSys = new Thread(new ThreadStart(InitSystem));
Thread_InitSys.Start();
下面是initSystem函数的申明: private void InitSystem()
{
setTextBox("321");
Thread.Sleep(10000);
SetTextBox("Test");
Thread.Sleep(10000);
setTextBox("12131424"); }
{
TextBox1.Text = "321";
..如何暂停10秒后,继续执行
TextBox1.Text = "123";
}
我建议你还是用JS实现吧,或者加个AJAX控件....
using System.Threading;class Test
{
static void Main()
{
// To start a thread using a static thread procedure, use the
// class name and method name when you create the ThreadStart
// delegate. Beginning in version 2.0 of the .NET Framework,
// it is not necessary to create a delegate explicitly.
// Specify the name of the method in the Thread constructor,
// and the compiler selects the correct delegate. For example:
//
// Thread newThread = new Thread(Work.DoWork);
//
ThreadStart threadDelegate = new ThreadStart(Work.DoWork);
Thread newThread = new Thread(threadDelegate);
newThread.Start(); // To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ThreadStart delegate. Beginning in version
// 2.0 of the .NET Framework, the explicit delegate is not
// required.
//
Work w = new Work();
w.Data = 42;
threadDelegate = new ThreadStart(w.DoMoreWork);
newThread = new Thread(threadDelegate);
newThread.Start();
}
}class Work
{
public static void DoWork()
{
Console.WriteLine("Static thread procedure.");
}
public int Data;
public void DoMoreWork()
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}
}/* This code example produces the following output (the order
of the lines might vary):
Static thread procedure.
Instance thread procedure. Data=42
*/
using System.Threading;public class Work
{
public static void Main()
{
// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate. C# infers the
// appropriate delegate creation syntax:
// new ParameterizedThreadStart(Work.DoWork)
//
Thread newThread = new Thread(Work.DoWork); // Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread.Start(42); // To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate. C# infers
// the appropriate delegate creation syntax:
// new ParameterizedThreadStart(w.DoMoreWork)
//
Work w = new Work();
newThread = new Thread(w.DoMoreWork); // Pass an object containing data for the thread.
//
newThread.Start("The answer.");
} public static void DoWork(object data)
{
Console.WriteLine("Static thread procedure. Data='{0}'",
data);
} public void DoMoreWork(object data)
{
Console.WriteLine("Instance thread procedure. Data='{0}'",
data);
}
}/* This code example produces the following output (the order
of the lines might vary):Static thread procedure. Data='42'
Instance thread procedure. Data='The answer'
*/