主頁 > .NET開發 > C# IO流與檔案讀寫學習筆記

C# IO流與檔案讀寫學習筆記

2020-09-20 01:29:12 .NET開發

    本筆記摘抄自:https://www.cnblogs.com/liyangLife/p/4797583.html,記錄一下學習程序以備后續查用,

    一、檔案系統

    1.1檔案系統類的介紹

    檔案操作類大都在System.IO命名空間里,FileSystemInfo類是所有檔案系統類的基類,FileInfo與File表示檔案系統中的檔案,DirectoryInfo與Directory

表示檔案系統中的檔案夾,Path表示檔案系統中的路徑,DriveInfo提供對有關驅動器資訊的訪問,

    注意,XXXInfo與XXX類的區別是:XXX是靜態類,XXXInfo類可以實體化,還有個較為特殊的類System.MarshalByRefObject允許在支持遠程處理的

應用程式中跨應用程式域邊界訪問物件,

    1.2FileInfo與File類

    class Program
    {
        static void Main(string[] args)
        {
            #region FileInfo與File類
            //創建檔案
            FileInfo file = new FileInfo(@"E:\學習筆記\C#\Test.txt");
            FileStream fs = file.Create();
            //關閉檔案流,這個很重要,
            fs.Close();
            Console.WriteLine("創建時間:" + file.CreationTime);
            Console.WriteLine("檔案路徑:" + file.DirectoryName);
            //打開追加流
            StreamWriter sw = file.AppendText();
            //追加資料
            sw.Write("科比·布萊恩特");
            //釋放資源,關閉檔案,
            sw.Dispose();
            //移動
            File.Move(file.FullName, @"E:\學習筆記\Test.txt");
            Console.WriteLine("檔案創建并操作完成,");
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    1.3DirectoryInfo與Directory類

    class Program
    {
        static void Main(string[] args)
        {
            #region FileInfo與File類
            ////創建檔案
            //FileInfo file = new FileInfo(@"E:\學習筆記\C#\Test.txt");
            //FileStream fs = file.Create();
            ////關閉檔案流,這個很重要,
            //fs.Close();
            //Console.WriteLine("創建時間:" + file.CreationTime);
            //Console.WriteLine("檔案路徑:" + file.DirectoryName);
            ////打開追加流
            //StreamWriter sw = file.AppendText();
            ////追加資料
            //sw.Write("科比·布萊恩特");
            ////釋放資源,關閉檔案,
            //sw.Dispose();
            ////移動
            //File.Move(file.FullName, @"E:\學習筆記\Test.txt");
            //Console.WriteLine("檔案創建并操作完成,");
            //Console.Read();
            #endregion

            #region DirectoryInfo與Directory類
            //創建檔案夾
            DirectoryInfo directory = new DirectoryInfo(@"E:\學習筆記\C#\Test");
            directory.Create();
            Console.WriteLine("父檔案夾:" + directory.Parent.FullName);
            //輸出父目錄下的所有檔案夾與檔案
            FileSystemInfo[] infos = directory.Parent.GetFileSystemInfos();
            foreach (FileSystemInfo info in infos)
            {
                Console.WriteLine(info.Name);
            }
            //洗掉檔案夾
            Directory.Delete(directory.FullName);
            Console.WriteLine("檔案夾創建并操作完成,");
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    1.4Path類

    class Program
    {
        static void Main(string[] args)
        {
            #region Path類
            //連接
            Console.WriteLine(Path.Combine(@"E:\學習筆記\C#", @"Test.txt"));
            Console.WriteLine("平臺特定的字符:" + Path.DirectorySeparatorChar);
            Console.WriteLine("平臺特定的替換字符:" + Path.AltDirectorySeparatorChar);
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    1.5DriveInfo類

    class Program
    {
        static void Main(string[] args)
        {
            #region DriveInfo類
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.IsReady)
                {
                    Console.WriteLine("驅動器名稱:" + drive.Name);
                    Console.WriteLine("驅動器型別:" + drive.DriveFormat);
                    Console.WriteLine("總容量:" + drive.TotalFreeSpace);
                    Console.WriteLine("可用容量:" + drive.AvailableFreeSpace + "\n");


                }
            }
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    二、檔案操作

    2.1檔案的移動、復制、洗掉

    class Program
    {
        static void Main(string[] args)
        {
            #region 檔案的移動、復制、洗掉
            string path = @"E:\學習筆記\Test.txt";

            File.WriteAllText(path, "測驗資料");
            Console.WriteLine("檔案已寫入,");

            File.Move(path, @"E:\學習筆記\C#\Test.txt");
            Console.WriteLine("檔案已移動,");

            File.Copy(@"E:\學習筆記\C#\Test.txt", path);
            Console.WriteLine("檔案已復制,");

            File.Delete(@"E:\學習筆記\C#\Test.txt");
            Console.WriteLine("檔案已洗掉,");

            Console.Read();
            #endregion
        }
    }
View Code

    2.2判斷路徑是檔案還是檔案夾

    class Program
    {
        static void Main(string[] args)
        {
            #region 判斷路徑是檔案還是檔案夾
            IsFile(@"E:\學習筆記\Test.txt");
            IsFile(@"E:\學習筆記\");
            IsFile(@"E:\學習筆記\XXX");
            Console.Read();
            #endregion
        }

        /// <summary>
        /// 判斷路徑是檔案還是檔案夾
        /// </summary>
        /// <param name="path"></param>
        static void IsFile(string path)
        {
            if (File.Exists(path))
            {
                Console.WriteLine("這是個檔案,");
            }
            else if (Directory.Exists(path))
            {
                Console.WriteLine("這是個檔案夾,");
            }
            else
            {
                Console.WriteLine("路徑不存在,");
            }
        }
    }
View Code

    運行結果如下:

    三、檔案讀寫與資料流

    3.1檔案讀取

    class Program
    {
        static void Main(string[] args)
        {
            #region 檔案讀取
            string path = @"E:\學習筆記\Test.txt";
            byte[] bytes = File.ReadAllBytes(path);
            Console.WriteLine("ReadAllBytes讀二進制:");
            foreach (byte b in bytes)
            {
                Console.Write((char)b);
            }
            Console.WriteLine(Environment.NewLine);

            string[] strs = File.ReadAllLines(path, Encoding.UTF8);
            Console.WriteLine("ReadAllLines讀所有行:");
            foreach (string s in strs)
            {
                Console.WriteLine(s + "\n");
            }

            string str = File.ReadAllText(path, Encoding.UTF8);
            Console.WriteLine("ReadAllText讀所有行:\n" + str);
            Console.Read();
            #endregion
        }
    }
View Code

   運行結果如下:

    3.2檔案寫入

    class Program
    {
        static void Main(string[] args)
        {
            #region 檔案寫入
            string path = @"E:\學習筆記\Test.txt";
            File.WriteAllBytes(path, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });  //寫入二進制
            Console.WriteLine("WriteAllBytes寫入二進制成功,");

            string[] array = { "123", "456", "789" };
            File.WriteAllLines(path, array, Encoding.UTF8);                         //寫入所有行
            Console.WriteLine("WriteAllLines寫入所有行成功,");

            File.WriteAllText(path, "Hello World", Encoding.UTF8);                  //寫入字串
            Console.WriteLine("WriteAllText寫入字串成功,\n");

            Console.Read();
            #endregion
        }
    }
View Code

    3.3資料流

    FileStream:檔案流,可以讀寫二進制檔案,

    StreamReader:流讀取器,使其以一種特定的編碼從位元組流中讀取字符,

    StreamWriter:流寫入器,使其以一種特定的編碼向流中寫入字符,

    BufferedStream:緩沖流,給另一流上的讀寫操作添加一個緩沖層,

    3.3.1使用FileStream讀寫二進制檔案

    class Program
    {
        static void Main(string[] args)
        {
            #region 使用FileStream讀寫二進制檔案
            string path = @"E:\學習筆記\C#\Test.txt";
            //以寫檔案的方式創建檔案
            FileStream file = new FileStream(path, FileMode.CreateNew, FileAccess.Write);
            string str = "科比·布萊恩特";
            byte[] bytes = Encoding.Unicode.GetBytes(str);
            //寫入二進制
            file.Write(bytes, 0, bytes.Length);
            file.Dispose();
            Console.WriteLine("寫入資料成功!!!");
            //以讀檔案的方式打開檔案
            file = new FileStream(path, FileMode.Open, FileAccess.Read);
            byte[] temp = new byte[bytes.Length];
            //讀取二進制
            file.Read(temp, 0, temp.Length);
            Console.WriteLine("讀取資料:" + Encoding.Unicode.GetString(temp));
            file.Dispose();
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    3.3.2StreamWriter與StreamReader

    使用StreamWriterStreamReader就不用擔心文本檔案的編碼方式,所以它們很適合讀寫文本檔案,

    class Program
    {
        static void Main(string[] args)
        {
            #region StreamWriter與StreamReader
            string path = @"E:\學習筆記\C#\Test1.txt";
            //以寫檔案的方式創建檔案
            FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(file);
            sw.WriteLine("科比·布萊恩特");
            sw.Dispose();
            Console.WriteLine("寫入資料成功!!!");
            //以讀檔案的方式打開檔案
            file = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(file);
            Console.WriteLine("讀取資料:" + sr.ReadToEnd());
            sr.Dispose();
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

   四、記憶體映射檔案

    MemoryMappedFile類(.NET4新增):

    應用程式需要頻繁地或隨機地訪問檔案時,最好使用MemoryMappedFile類(映射記憶體的檔案),使用這種方式允許把檔案的一部分或者全部加載到一段

虛擬記憶體上,這些檔案內容會顯示給應用程式,就好像這個檔案包含在應用程式的主記憶體中一樣,

    class Program
    {
        static void Main(string[] args)
        {
            #region 記憶體映射檔案
            MemoryMappedFile mmFile = MemoryMappedFile.CreateFromFile(@"E:\學習筆記\C#\Test2.txt", FileMode.OpenOrCreate, "MapName", 1024 * 1024);
            //記憶體映射檔案的視圖
            //或使用資料流操作記憶體檔案MemoryMappedViewStream stream = mmFile.CreateViewStream();
            MemoryMappedViewAccessor mmViewAccessor = mmFile.CreateViewAccessor();
            string str = "科比·布萊恩特";
            int length = Encoding.UTF8.GetByteCount(str);
            //寫入資料
            mmViewAccessor.WriteArray<byte>(0, Encoding.UTF8.GetBytes(str), 0, length);
            byte[] bytes = new byte[length];
            mmViewAccessor.ReadArray<byte>(0, bytes, 0, bytes.Length);
            Console.WriteLine(Encoding.UTF8.GetString(bytes));
            //釋放資源
            mmFile.Dispose();
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    五、檔案安全

    5.1ACL介紹

    ACL是存在于計算機中的一張表(訪問控制表),它使作業系統明白每個用戶對特定系統物件--例如檔案目錄或單個檔案的存取權限,每個物件擁有一個在

訪問控制表中定義的安全屬性,每個系統用戶對于這張表擁有一個訪問權限,最一般的訪問權限包括讀檔案(包括所有目錄中的檔案)、寫一個或多個檔案

和執行一個檔案(如果它是一個可執行檔案或者是程式的時候),

    5.2讀取檔案的ACL

    class Program
    {
        static void Main(string[] args)
        {
            #region 讀取檔案的ACL
            FileStream file = new FileStream(@"E:\學習筆記\Test.txt", FileMode.Open, FileAccess.Read);
            //得到檔案訪問控制屬性
            FileSecurity filesec = file.GetAccessControl();
            //輸出檔案的訪問控制項
            foreach (FileSystemAccessRule filerule in filesec.GetAccessRules(true, true, typeof(NTAccount)))
            {
                Console.WriteLine(filerule.AccessControlType + "--" + filerule.FileSystemRights + "--" + filerule.IdentityReference);
            }
            file.Dispose();
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    5.3讀取檔案夾的ACL

    class Program
    {
        static void Main(string[] args)
        {
            #region 讀取檔案夾的ACL
            DirectoryInfo dir = new DirectoryInfo(@"E:\學習筆記\C#\");
            //得到檔案訪問控制屬性
            DirectorySecurity filesec = dir.GetAccessControl();
            //輸出檔案的訪問控制項
            foreach (FileSystemAccessRule filerule in filesec.GetAccessRules(true, true, typeof(NTAccount)))
            {
                Console.WriteLine(filerule.AccessControlType + "--" + filerule.FileSystemRights + "--" + filerule.IdentityReference);
            }
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    5.4修改ACL

    class Program
    {
        static void Main(string[] args)
        {
            #region 修改ACL
            FileStream file = new FileStream(@"E:\學習筆記\Test.txt", FileMode.Open, FileAccess.Read);
            //得到檔案訪問控制屬性
            FileSecurity filesec = file.GetAccessControl();
            //輸出檔案訪問控制項
            PrintACL(filesec.GetAccessRules(true, true, typeof(NTAccount)));
            FileSystemAccessRule rule = new FileSystemAccessRule
                (
                    new NTAccount(@"AtomyStudio\Administrator"),                //計算機賬戶名
                    FileSystemRights.Delete,                                    //操作權限
                    AccessControlType.Allow                                     //能否訪問受保護的物件
                );
            filesec.AddAccessRule(rule);                                        //增加ACL項
            PrintACL(filesec.GetAccessRules(true, true, typeof(NTAccount)));    //輸出檔案訪問控制項
            filesec.RemoveAccessRule(rule);                                     //移除ACL項
            PrintACL(filesec.GetAccessRules(true, true, typeof(NTAccount)));    //輸出檔案訪問控制項
            file.Dispose();
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

    六、讀寫注冊表

    6.1注冊表介紹

    Windows注冊表是幫助Windows控制硬體、軟體、用戶環境和Windows界面的一套資料檔案,運行regedit可以看到有5個注冊表配置單元(實際有7個):

    HKEY-CLASSES-ROOT: 檔案關聯和COM資訊

    HKEY-CURRENT-USER: 用戶輪廓

    HKEY-LOCAL-MACHINE: 本地機器系統全域配置子鍵

    HKEY-USERS: 已加載用戶輪廓子鍵

    HKEY-CURRENT-CONFIG: 當前硬體配置

    6.2.NET操作注冊表的類

    在.NET中提供了Registry類、RegistryKey類來實作對注冊表的操作,

    6.2.1Registry類

    封裝了注冊表的七個基本主鍵:

    Registry.ClassesRoot 對應于HKEY_CLASSES_ROOT主鍵

    Registry.CurrentUser 對應于HKEY_CURRENT_USER主鍵

    Registry.LocalMachine 對應于HKEY_LOCAL_MACHINE主鍵

    Registry.User 對應于HKEY_USER主鍵

    Registry.CurrentConfig 對應于HEKY_CURRENT_CONFIG主鍵

    Registry.DynDa 對應于HKEY_DYN_DATA主鍵

    Registry.PerformanceData 對應于HKEY_PERFORMANCE_DATA主鍵

    6.2.2RegistryKey類

    封裝了對注冊表的基本操作,包括讀取、寫入,洗掉,

    1)讀取的函式:

    OpenSubKey() 主要是打開指定的子鍵

    GetSubKeyNames() 獲得主鍵下面的所有子鍵的名稱,它的回傳值是一個字串陣列,

    GetValueNames() 獲得當前子鍵中的所有的鍵名稱,它的回傳值也是一個字串陣列,

    GetValue() 指定鍵的鍵值,

    2)寫入的函式:

    CreateSubKey() 增加一個子鍵

    SetValue() 設定一個鍵的鍵值

    3)洗掉的函式:

    DeleteSubKey() 洗掉一個指定的子鍵

    DeleteSubKeyTree() 洗掉該子鍵以及該子鍵以下的全部子鍵

    6.3示例

    class Program
    {
        static void Main(string[] args)
        {
            #region 讀寫注冊表
            string path = @"SOFTWARE\Microsoft\Internet Explorer\Extension Compatibility";
            //以只讀方式
            RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(path, true);
            if (registryKey != null)
            {
                Console.WriteLine(registryKey.Name + "--" + registryKey.SubKeyCount + "--" + registryKey.ValueCount);
                string subRegistryKey = Guid.NewGuid().ToString();
                //增加一個子鍵
                registryKey.CreateSubKey(subRegistryKey);
                RegistryKey newRegistryKey = Registry.LocalMachine.OpenSubKey(path + @"\" + subRegistryKey, true);
                //設定一個鍵的鍵值
                newRegistryKey.SetValue("姓名", "科比");
                //設定一個鍵的鍵值
                newRegistryKey.SetValue("鍵名", "布萊恩特");
                Console.WriteLine(registryKey.Name + "--" + registryKey.SubKeyCount + "--" + registryKey.ValueCount);
                registryKey.Close();
                newRegistryKey.Close();
            }
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果生成值為:

    七、讀寫獨立的存盤器

    7.1IsolatedStorageFile類

    使用IsolatedStorageFile類可以讀寫獨立的存盤器,

    獨立的存盤器可以看成一個虛擬磁盤,在其中可以保存只由創建他們的應用程式或其應用程式實體共享的資料項,

    獨立的存盤器的訪問型別有兩種:第一種是一個應用程式的多個實體在同一個獨立存盤器中作業,第二種是一個應用程式的多個實體在各自不同的獨立存

儲器中作業,

    7.2示例

    class Program
    {
        static void Main(string[] args)
        {
            #region 讀寫獨立的存盤器
            //寫檔案
            IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(@"Test.txt", FileMode.Create, FileAccess.Write);
            string str = "科比·布萊恩特";
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            //寫資料
            fileStream.Write(bytes, 0, bytes.Length);
            fileStream.Dispose();
            //讀檔案
            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForDomain();
            string[] fileNames = file.GetFileNames(@"Test.txt");
            foreach (string fileName in fileNames)
            {
                Console.WriteLine(fileName);
                fileStream = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fileStream);
                Console.WriteLine("讀取檔案:" + sr.ReadToEnd());
                sr.Dispose();
                //洗掉檔案
                file.DeleteFile(fileName);
            }
            file.Dispose();
            Console.WriteLine("OK!");
            Console.Read();
            #endregion
        }
    }
View Code

    運行結果如下:

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/84745.html

標籤:C#

上一篇:C# compare different Encoding pattern between UTF8 and UTF32 based on Md5

下一篇:C#登出系統并清除Cookie

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more