昨天下面这篇文章gomoku已经帮我解决!
http://topic.csdn.net/u/20081118/12/bd5a353e-7788-414e-b95a-5babd7a596c0.html?seed=1159877965
private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(this.DoWork);
} void DoWork(object state)
{
AllocConsole();
for (int i = 0; i < 100; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(500);
}
FreeConsole();
} [DllImport("Kernel32.dll")]
static extern bool AllocConsole();
[DllImport("Kernel32.dll")]
static extern bool FreeConsole();
但是我在程序开始的时候读取了一个BIN文件
使用了Console.WriteLine(string);
结果在控制台显示的时候里面没有数值显示~
请高手指教!
http://topic.csdn.net/u/20081118/12/bd5a353e-7788-414e-b95a-5babd7a596c0.html?seed=1159877965
private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(this.DoWork);
} void DoWork(object state)
{
AllocConsole();
for (int i = 0; i < 100; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(500);
}
FreeConsole();
} [DllImport("Kernel32.dll")]
static extern bool AllocConsole();
[DllImport("Kernel32.dll")]
static extern bool FreeConsole();
但是我在程序开始的时候读取了一个BIN文件
使用了Console.WriteLine(string);
结果在控制台显示的时候里面没有数值显示~
请高手指教!
解决方案 »
- GDI: drawline怎么划线在屏幕最前方(实现在panel的范围内画一条线,panel上有若干控件了label,textbox等等)?
- windows mobile中 制作数字键盘
- WebBrowser响应事件问题 50分向高人求教 在线等
- 子窗体最大化问题
- div问题?
- devexpress grid 如何隐藏grid中的某一行(并不是从数据源中删除)
- float类型数据转成string类型后 精度减弱
- 请人帮忙写个程序
- 再问问,最好给点代码。
- 如何定义一个sqlconnection类,可以让该namespace下的其他类可以访问
- 求教:客户端、服务器聊天程序中的一个问题
- 急!!!WebClient下载url不支持中文,如何解决?
private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(this.DoWork);
} void DoWork(object state)
{
AllocConsole();
for (int i = 0; i < 100; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(500);
}
FreeConsole();
} [DllImport("Kernel32.dll")]
static extern bool AllocConsole();
[DllImport("Kernel32.dll")]
static extern bool FreeConsole();兄弟忽悠人哦,被你搞晕了,还以为是B/S的,我测试了,可以打印的啊
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.Remoting;
using System.Reflection;
using System.Runtime.InteropServices;namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(this.DoWork);
} void DoWork(object state)
{
AllocConsole();
for (int i = 0; i < 100; i++)
{
Console.WriteLine(i.ToString());
Thread.Sleep(500);
}
FreeConsole();
} [DllImport("Kernel32.dll")]
static extern bool AllocConsole();
[DllImport("Kernel32.dll")]
static extern bool FreeConsole();
}
}上面是全部代码.可以打印的.
但是我在执行这个按钮之前,
在程序的一开始读了一个BIN文件
其中有Console.WriteLine(getstring);
要是一开始的时候把这句话去了~运行正常!但是要加上就出问题!
{
string GetString;
try
{
using(StreamReader sr=new StreamReader("abc.bin",encoding.GetEncoding("gb2312")))
{
while(sr.ReadLine()!=null)
{
Console.WriteLine(GetString);//加上这句话就不行
.........
.....
}
}
}
}
Project => Properties => Application => Output type: Console Application.By doing so, you will have a console attached at the first begining.
Since now you have a console, you don't need to AllocConsole() and FreeConsole().
You can delete these two lines.