昨天下面这篇文章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);
结果在控制台显示的时候里面没有数值显示~
请高手指教!

解决方案 »

  1.   

    你确定执行到了Console.WriteLine(i.ToString())这一句?
      

  2.   

    Console是控制台程序用于输出的,你这个都有按钮,显然不是控制台程序,应该用Response。
      

  3.   


     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的,我测试了,可以打印的啊
      

  4.   


    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();
        }
    }上面是全部代码.可以打印的.
      

  5.   

    上边的代码没有问题!
    但是我在执行这个按钮之前,
    在程序的一开始读了一个BIN文件
    其中有Console.WriteLine(getstring);
    要是一开始的时候把这句话去了~运行正常!但是要加上就出问题!
      

  6.   

    那你得把你读BIN文件的代码也发出来啊
      

  7.   

    wangping_li 那个代码如果加上private void form1_load(.....)
    {
    string GetString;
    try
    {
    using(StreamReader sr=new StreamReader("abc.bin",encoding.GetEncoding("gb2312")))
    {
    while(sr.ReadLine()!=null)
    {
    Console.WriteLine(GetString);//加上这句话就不行
    .........
    .....
    }
    }
    }
    }
      

  8.   

    WinForm doesn't have a console (the black dos window), but Console programs have one.If you need the console window all the time, then change your project setting to console application:
    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.
      

  9.   

    不行是不能执行的意思吗?报错了吗?报的什么错?我看你的代码中,没有给GetString赋值的地方啊?我记得这样编译是会有警告的。就算没有警告,也只是写一个空串,怎么会有显示捏?!