private void btnStart_Click(object sender, EventArgs e)
{
if (btnStart.Text == "开始")
{
btnStart.Text = "暂停";
flag = true;
}
else
{
btnStart.Text = "开始";
flag = false;
}
CreateThread();
}
private void CreateThread()
{
dothread = new DoThread();
Thread thread = new Thread(new ThreadStart(dothread.interfaceMsg));
Thread threadTwo = new Thread(new ThreadStart(MsgTwo));
thread.Start();
threadTwo.Start();
}
public void MsgTwo()
{
while (flag)
{
ListViewBind();
}
}
private void ListViewBind()
{
Thread.Sleep(1000);
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(ListViewBind));
}
else
{
}
private void BtnBegin_Click(object sender, EventArgs e)
{
Thread threadOne = new Thread(new ThreadStart(ListViewLog));
threadOne.Start();
}
private void ListViewLog()
{
int count = 0;
this.saveFileDialog1.DefaultExt = ".txt";
saveFileDialog1.Filter = "Word文件(*.doc)|*.doc|文本文件(*.txt)|*.txt|所有合适文件(*.doc/*.txt)|*.doc/*.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
while (count < this.listView2.Items.Count)
{
sw.WriteLine(listView2.Items[count].SubItems[1].Text.Trim());
count = count + 1;
}
sw.Flush();
fs.Close();
}
}
当运行这段代码的时候会在if (saveFileDialog1.ShowDialog() == DialogResult.OK)
出现
在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
{
if (btnStart.Text == "开始")
{
btnStart.Text = "暂停";
flag = true;
}
else
{
btnStart.Text = "开始";
flag = false;
}
CreateThread();
}
private void CreateThread()
{
dothread = new DoThread();
Thread thread = new Thread(new ThreadStart(dothread.interfaceMsg));
Thread threadTwo = new Thread(new ThreadStart(MsgTwo));
thread.Start();
threadTwo.Start();
}
public void MsgTwo()
{
while (flag)
{
ListViewBind();
}
}
private void ListViewBind()
{
Thread.Sleep(1000);
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(ListViewBind));
}
else
{
}
private void BtnBegin_Click(object sender, EventArgs e)
{
Thread threadOne = new Thread(new ThreadStart(ListViewLog));
threadOne.Start();
}
private void ListViewLog()
{
int count = 0;
this.saveFileDialog1.DefaultExt = ".txt";
saveFileDialog1.Filter = "Word文件(*.doc)|*.doc|文本文件(*.txt)|*.txt|所有合适文件(*.doc/*.txt)|*.doc/*.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
while (count < this.listView2.Items.Count)
{
sw.WriteLine(listView2.Items[count].SubItems[1].Text.Trim());
count = count + 1;
}
sw.Flush();
fs.Close();
}
}
当运行这段代码的时候会在if (saveFileDialog1.ShowDialog() == DialogResult.OK)
出现
在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常。
解决方案 »
- vss下对一网站用断点调试不可用
- windows7 64位系统下不能安装Visual Studio 2008 文档
- visual stdio 2010用鼠标选中代码进行复制或粘贴时,窗口就会不停抖动
- 高手帮忙一下,为什么我安装VS2005老装不上。
- 如何实现TabControl中页的切换
- 控制台程序问题
- 在不同程序集使用:Object obj=Activator.CreateInstance(Type type)创建对象 怎么出现错误呢!
- 如何区分DataGrid控件中多个选择列?在线等,谢谢!
- 关于IE浏览器中后退按钮的问题
- 错因:访问 IIS 元数据库失败,我是先安装的VS2008,然后安装的IIS6.0,通过网上查找的一些方法仍不奏效
- 关于关闭一个窗体的程序
- datagridview 绑定List<T> 其中某项需要使用combobox怎么实现
class ThreadProces
{
string strPath;//待处理的路径
Thread m_thread;
public ThreadProcess( string path )
{
strPath = path;
m_thread = new Thread(new ThreadStart(Run) );
m_thread.Start();
} private void Run( object o )
{
处理搜索,引发搜索处理事件信息,供UI层显示调用
}}