小弟不才!想问一下关于C# 在进程 ThreadStart 开始时候怎么去读INI的所有数据

解决方案 »

  1.   

    。不好意思  沒說清楚就發出來了!就是我啟動一個線程 然後怎麼讓線程開始的時候去讀到這個Ini文件並且返回他的參數
      

  2.   

    读ini参考
    http://topic.csdn.net/u/20090102/19/7818ea87-13a3-4fac-a370-436db647fcc2.html不过现在都用config文件了。
      

  3.   

    关键两个API函数:       [DllImport("kernel32")]
            public static extern long WritePrivateProfileString(string section, string key, 
                                                                 string val, string filePath);
            /*参数说明:section:INI文件中的段落;key:INI文件中的关键字;
              val:INI文件中关键字的数值;filePath:INI文件的完整的路径和名称。*/
            [DllImport("kernel32")]
            public static extern int GetPrivateProfileString(string section, string key, 
                                                              string def, StringBuilder retVal, 
                                                              int size, string filePath);
            /*参数说明:section:INI文件中的段落名称;key:INI文件中的关键字;
              def:无法读取时候时候的缺省数值;retVal:读取数值;size:数值的大小;
              filePath:INI文件的完整路径和名称。*/
      

  4.   

    自动登录 获取 用户名和密码吗 我可以给个例子 读配置文件 config的
      

  5.   

    读写INI文件单独用一个类,然后你启动一个线程,然后调用方法将数据读取出来即可。
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.IO;/// <summary>
    /// INI文件读写类。
    /// </summary>
    public class INIFile
    {
        public string path;    public INIFile(string INIPath)
        {
            path = INIPath;
        }    [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);    [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
        /// <summary>
        /// 写INI文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }    /// <summary>
        /// 读取INI文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
            return temp.ToString();
        }
        public byte[] IniReadValues(string section, string key)
        {
            byte[] temp = new byte[255];
            int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
            return temp;    }
        /// <summary>
        /// 删除ini文件下所有段落
        /// </summary>
        public void ClearAllSection()
        {
            IniWriteValue(null, null, null);
        }
        /// <summary>
        /// 删除ini文件下personal段落下的所有键
        /// </summary>
        /// <param name="Section"></param>
        public void ClearSection(string Section)
        {
            IniWriteValue(Section, null, null);
        }
    }
      

  6.   

    读ini 你不是已经会了么?返回他的參數 要给谁?你直接说你要实现什么功能吧
      

  7.   

    谢谢你们,你们说的都对的!但是我现在有一个INI的类using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Windows.Forms;namespace YHplc
    {
        public class INI
        {
            public string FileName;
            [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);        public INI(string AFileName)
            {        }        public void IniwriteValue(string Section, string key, string Value)
            {
                WritePrivateProfileString(Section, key, Value, FileName);
            }        public string IniReadValueString(string Section, string key)
            {
                byte[] Buffer = new byte[65535];
                int i = GetPrivateProfileString(Section, key, "", Buffer, Buffer.GetUpperBound(0), FileName);
                string s = Encoding.GetEncoding(0).GetString(Buffer);
                s = s.Substring(0, i);
                return s.Trim();
            }        public bool ExistINIFile()
            {
                return File.Exists(FileName);
            }
        }
    然后我在另一个COMClass类里面去调用他,但是我需要线程,要线程开始的时候然后去执行调用INI这个类顺便弱弱的问一下,如果我的INI文档里面有这么一段Get X Data = X0,X1,X2,X3,X4,X5,X6,X7
    那么我取到的Vlase的值肯定是X0,X1,X2,X3,X4,X5,X6,X7
    然后我应该怎么用ArrayList将这些用逗号去隔开呢!就这两个问题!麻烦再回答一下好吗?在线等 拜托了
      

  8.   

    我实在搞不懂,你到底要问的什么第一个问题,你的thread的proc函数中写上读取ini的操作不久不好了?第二个问题,ini中读出来的逗号分隔的字符串,使用split,然后使用arrylist.addrange不就好了?