当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.StreamWriter.Dispose方法代码示例

本文整理汇总了C#中System.IO.StreamWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.Dispose方法的具体用法?C# System.IO.StreamWriter.Dispose怎么用?C# System.IO.StreamWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamWriter的用法示例。


在下文中一共展示了System.IO.StreamWriter.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Error

 public void Error(Exception ex)
 {
     string str1 = this.formatMessage("error", ex.ToString());
     System.Threading.Monitor.Enter(lockObject);
     try
     {
         try
         {
             System.IO.TextWriter textwriter1 = new System.IO.StreamWriter(this.logFile, true);
             try
             {
                 textwriter1.WriteLine(str1);
             }
             finally
             {
                 if (textwriter1 != null)
                 {
                     textwriter1.Dispose();
                 }
             }
         }
         catch (Exception exception)
         {
             Exception exception1 = exception;
             Console.WriteLine("ERROR: Cannot write log to " + this.logFile + "." + exception1.ToString());
         }
     }
     finally
     {
         System.Threading.Monitor.Exit(lockObject);
     }
 }
开发者ID:reinkrul,项目名称:SailorsTabDotNet,代码行数:32,代码来源:Log.cs

示例2: LoadClues

        // this code is modfied code from the following tutorial
        // http://blogs.msdn.com/b/mingfeis_code_block/archive/2010/10/03/windows-phone-7-how-to-store-data-and-pass-data-between-pages.aspx
        public void LoadClues()
        {
            EnterClues();
            string elementNumber;

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                for (int i=0; i < noClues; i++)
                {
                    elementNumber = "number"+clueId[i].ToString();
                    XDocument _doc = new XDocument();
                    XElement _clue = new XElement(elementNumber);
                    XAttribute _clueId = new XAttribute("clueId", clueId[i]);
                    XAttribute _clueText = new XAttribute("clueText", clueText[i]);
                    XAttribute _barcodeRef = new XAttribute("barcodeRef", barcodeRef[i]);
                    XAttribute _location = new XAttribute("location", location[i]);
                    XAttribute _locInfo = new XAttribute("locInfo", locInfo[i]);
                    XAttribute _latitude = new XAttribute("latitude", latitude[i]);
                    XAttribute _longitude = new XAttribute("longitude", longitude[i]);

                    _clue.Add(_clueId, _clueText, _barcodeRef, _location, _locInfo, _latitude, _longitude);

                    _doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), _clue);
                    IsolatedStorageFileStream memory = new IsolatedStorageFileStream(elementNumber + ".clue", System.IO.FileMode.Create, storage);

                    System.IO.StreamWriter file = new System.IO.StreamWriter(memory);
                    _doc.Save(file);

                    file.Dispose();
                    memory.Dispose();
                }

            }
        }
开发者ID:borgidiom,项目名称:UC-Scanager-Hunt,代码行数:36,代码来源:Clues.cs

示例3: writeReadFile

            public writeReadFile()
            {

                //Create a try catch block to make sure that that memory is recoverted. 
                try
                {
                    //Tell the user about writing a new file.
                    Console.WriteLine("Press any key to write a random double file to the same directory.");
                    Console.ReadKey();
                    using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter("fileOfGarbage.txt"))
                    {
                        //Create a new random double.
                        Random randGarbageDouble = new Random();
                        //Write random generated numbers to the text file
                        for (int countToGarbageTotalNumber = 0; countToGarbageTotalNumber < 10000000; countToGarbageTotalNumber++)
                        {
                            streamWriter.WriteLine((randGarbageDouble.NextDouble() * (99999999999.999999 - 1) + 1).ToString());
                        }
                        showMemoryUsage();
                        //Flush, dispose, and Close the stream writer.
                        streamWriter.Flush();
                        streamWriter.Dispose();
                        streamWriter.Close();
                        showMemoryUsage();
                    }
                    showMemoryUsage();
                    Console.WriteLine("Press any key to read the random double file in the same directory.");
                    Console.ReadKey();
                    //Create a new double to be collected.
                    double[] garbageArrayString = new double[10000000];
                    //Read everything that was written into an array.
                    using (System.IO.StreamReader streamReader = new System.IO.StreamReader("fileOfGarbage.txt"))
                    {
                        //Create a string to hold the line
                        string line;
                        //create an int to hold the linecount
                        int countOfGarbageLine = 0;
                        while ((line = streamReader.ReadLine()) != null)
                        {
                            garbageArrayString[countOfGarbageLine++] = double.Parse(line);
                        }
                        showMemoryUsage();
                        //Flush, dispose, and Close the stream writer.
                        streamReader.Dispose();
                        streamReader.Close();
                        //Nullify the garbage array string for collection.
                        garbageArrayString = null;
                        countOfGarbageLine = 0;
                        showMemoryUsage();
                    }
                }
                //Finally is not needed as variables are cleared in the using statements.
                finally
                {
                    //Run garbage collection to be sure.
                    GC.Collect();
                    showMemoryUsage();
                }
            }
开发者ID:DevPump,项目名称:COP2362C,代码行数:59,代码来源:Program.cs

示例4: Write

 public void Write() {
     using (var writer = new System.IO.StreamWriter(env.ROOT + "log", true)) {
         for (int i = 0; i < queue.Count; ++i)
             writer.Write(queue[i]);
         writer.Dispose();
     }
     queue.Clear();
 }
开发者ID:Ghost53574,项目名称:CSdk,代码行数:8,代码来源:Logger.cs

示例5: addToFile

 private void addToFile(string ln)
 {
     System.IO.FileStream txt = new System.IO.FileStream("logsg.txt", System.IO.FileMode.Append);
     System.IO.StreamWriter trw = new System.IO.StreamWriter(txt);
     trw.WriteLine(ln);
     trw.Close();
     trw.Dispose();
 }
开发者ID:AndrewEastwood,项目名称:desktop,代码行数:8,代码来源:Com_SecureRuntime.cs

示例6: PrintData

 public static void PrintData(string path = "rf.dat")
 {
     System.IO.StreamWriter write = new System.IO.StreamWriter(path,false);
     foreach(string cmd in Commands)
     {
         write.WriteLine(cmd);
     }
     write.Dispose();
 }
开发者ID:lm458180997,项目名称:Touhou,代码行数:9,代码来源:Datas.cs

示例7: logErr

 static void logErr(string str)
 {
     string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
     string logPath = path + "\\Info-TC7.txt";
     System.IO.StreamWriter file = new System.IO.StreamWriter(logPath, true);
     file.WriteLine(str);
     file.Close();
     file.Dispose();
 }
开发者ID:vulamicy,项目名称:GitLamTest,代码行数:9,代码来源:Program.cs

示例8: Main

        static void Main(string[] args)
        {
            bool[] nullornot = new bool[10];
            // DefineTest.run();
            //Instruction ins = new Instruction(15, new string[] { "eax", "ecx" });
            //ins.printAssemblyInstruction();
            //ins.PrintBinaryInstruction();
            //Environment.Exit(0);
             //outloc = args[0] + ".lex";
            //Console.WriteLine(EnumKeywords.PUBLIC.ToString());
            //Console.ReadKey();
            //Environment.Exit(0);
            writer = new System.IO.StreamWriter(currentdir + args[0] + ".lex");
            lines = System.IO.File.ReadAllLines(currentdir + args[0]);
            //Console.WriteLine(operators.Count);
            //Console.WriteLine(keywords.Count);
            //Console.WriteLine(Convert.ToString((EnumOperator)1));
            for (int i = 0; i < lines.Length; i++)
            {
                //if(System.Text.RegularExpressions.Regex.IsMatch(lines[i], @"//.*|/\*([~/]|\*[~/])*\*+/"));
                //{
                //    continue;
                //}
                if (lines[i].StartsWith("//"))
                {
                    continue;
                }
                Console.WriteLine(lines[i]);
                Lexer.Start(ref lines, ref i,writer);
            }

            writer.Flush();
            writer.Close();
            writer.Dispose();
            Console.WriteLine("Lexical Analasis Complete");
            for (int i = 0; i < Lexer.pubtokenslist.Count; i++ )
            {
                for (int j = 0; j < Lexer.pubtokenslist.ElementAt<string[]>(i).Length; j++ )
                {
                    if (Lexer.pubtokenslist.ElementAt<string[]>(i)[j] == null)
                    {
                        nullornot[j] = true;
                    }
                }
                if (checknull(nullornot))
                {
                    continue;
                }
                AST<dynamic, dynamic, dynamic, dynamic> tokentree = new AST<dynamic, dynamic, dynamic, dynamic>(Lexer.pubtokenslist.ElementAt<string[]>(i));
                Parser parse = new Parser(tokentree,ref i);
            }

            Console.WriteLine("Compilation Complete");
            Console.WriteLine("Press Any Key To Exit");
            Console.ReadKey();
        }
开发者ID:06needhamt,项目名称:Stuffimake,代码行数:56,代码来源:Program.cs

示例9: writedebuglog

 public static void writedebuglog(string dblog) {
     System.IO.StreamWriter sw = new System.IO.StreamWriter("uwizard_debuglog.txt", true);
     sw.WriteLine("This debug log was generated by Uwizard " + getVerText(myversion) + " :");
     sw.WriteLine();
     sw.WriteLine(dblog);
     sw.WriteLine();
     sw.WriteLine();
     sw.Close();
     sw.Dispose();
 }
开发者ID:nastys,项目名称:Uwizard,代码行数:10,代码来源:Form1.cs

示例10: SplitCsv_byitemcount

        public static void SplitCsv_byitemcount(string file, string prefix, int itemcount)
        {
            // Read lines from source file
            string strDir = System.IO.Path.GetDirectoryName(file);
            string[] arr = System.IO.File.ReadAllLines(file);

            string headerrow = string.Empty;

            if (arr.LongLength > 0)
            {
                headerrow = arr[0];
            }

            int total = 0;
            int num = 0;
            var writer = new System.IO.StreamWriter(System.IO.Path.Combine(strDir, GetFileName(prefix, num)),true, System.Text.Encoding.UTF8);
            writer.WriteLine(headerrow);

            //Having Content in Array since first row is header
            if (arr.LongLength > 1)
            {
                for (int i = 1; i < arr.Length; i++)
                {

                    // Current line
                    string line = arr[i];
                    // Length of current line
                    int currentItemCount = i;

                    // See if adding this line would exceed the size threshold
                    if (total >= itemcount)
                    {
                        // Create a new file
                        num++;
                        total = 0;
                        writer.Dispose();
                        writer = new System.IO.StreamWriter(System.IO.Path.Combine(strDir, GetFileName(prefix, num)), true, System.Text.Encoding.UTF8);
                        writer.WriteLine(headerrow);
                    }
                    // Write the line to the current file
                    writer.WriteLine(line);

                    // Add item count
                    total += 1;

                }

            }
            // Loop through all source lines

            writer.Dispose();
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:52,代码来源:CSVSplit.cs

示例11: ClearLogFile

 public void ClearLogFile()
 {
     if (System.IO.File.Exists(settingsFile))
     {
         try
         {
             System.IO.StreamWriter fileWriter = new System.IO.StreamWriter(System.IO.Path.GetDirectoryName(executableURL) + "\\MomentumStrategyModule.log", false);
             fileWriter.WriteLine("");
             fileWriter.Dispose();
             fileWriter.Close();
         }
         finally {}
     }
 }
开发者ID:nklsrh,项目名称:SENG3011,代码行数:14,代码来源:Form1.cs

示例12: FrameIDFactory

        static FrameIDFactory()
        {
            CreateEntries();
            #if generate
            var writer = new System.IO.StreamWriter(@"C:\Temp\table.txt");
            _entries = new List<ID3v2FrameEntry>();

            var elements = Enum.GetNames(typeof(ID3v2FrameID));
            foreach (var element in elements)
            {
                var id = Enum.Parse(typeof(ID3v2FrameID), element);
                var id3v4ID = ID3v2FrameIDFactory.GetID((ID3v2FrameID)id, ID3Version.ID3v2_4);
                string id3v3ID;
                try
                {
                    id3v3ID = ID3v2FrameIDFactory.GetID((ID3v2FrameID)id, ID3Version.ID3v2_3);
                }
                catch (Exception)
                {
                    id3v3ID = null;
                }
                string id3v2ID;
                try
                {
                    id3v2ID = ID3v2FrameIDFactory.GetID((ID3v2FrameID)id, ID3Version.ID3v2_2);
                }
                catch (Exception)
                {
                    id3v2ID = null;
                }

                StringBuilder builder = new StringBuilder();
                builder.AppendLine("                entry = new ID3v2FrameEntry()");
                builder.AppendLine("                {");
                builder.AppendLine(String.Format("                    ID = ID3v2FrameID.{0},", ((ID3v2FrameID)id).ToString()));
                builder.AppendLine(String.Format("                    ID3v4ID = {0},", id3v4ID == null ? "null" : "\"" + id3v4ID + "\""));
                builder.AppendLine(String.Format("                    ID3v3ID = {0},", id3v3ID == null ? "null" : "\"" + id3v3ID + "\""));
                builder.AppendLine(String.Format("                    ID3v2ID = {0},", id3v2ID == null ? "null" : "\"" + id3v2ID + "\""));
                builder.AppendLine(String.Format("                    Desc = \"{0}\"", element));
                builder.AppendLine("                };");
                builder.AppendLine("                _entries.Add(entry);");
                writer.WriteLine(builder.ToString());
                writer.WriteLine();
                writer.WriteLine();
            }
            writer.Flush();
            writer.Dispose();
            #endif
        }
开发者ID:opcon,项目名称:cscore,代码行数:49,代码来源:FrameIDFactory.cs

示例13: WriteLog

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="path"></param>
        /// <param name="append"></param>
        /// <param name="ErrStr"></param>
        public static void WriteLog(string path, bool append, string ErrStr)
        {
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
            }
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, append))
            {
                writer.WriteLine(ErrStr);

                writer.Flush();

                writer.Dispose();
            }
        }
开发者ID:yimogit,项目名称:MyBlogFramework,代码行数:21,代码来源:FileHelper.cs

示例14: SaveArrayToFile

 public void SaveArrayToFile()
 {
     int count;
     var writer = new System.IO.StreamWriter("C:/calc/calculations.txt", false);
     for (count = 0; count <= Results.Length - 1; count++)
     {
         if (Results[count] == 0)
         {
             continue;
         }
         writer.Write(Results[count]);
         writer.WriteLine();
     }
     writer.Dispose();
 }
开发者ID:06needhamt,项目名称:Stuffimake,代码行数:15,代码来源:Form1.cs

示例15: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            string strPath = "";
            string strPathName = "";
            string strErrorMessage = "";

            if ((Server != null) && (Server.GetLastError() != null) && (Server.GetLastError().GetBaseException() != null))
            {
                System.Exception ex = Server.GetLastError().GetBaseException();

                strErrorMessage = "'<b>" + ex.Message + "'</b> Occured on " + System.DateTime.Now.ToString("yyyy/mm/dd - hh:mm:ss");
                strErrorMessage += "<br />Error Message: " + strErrorMessage;
                strErrorMessage += "<br />User IP: " + Request.UserHostAddress;
                strErrorMessage += "<br />Physical Path: " + Request.PhysicalPath;

                //Server.ClearError();

                Response.Write("<br />" + strErrorMessage + "<br /><br />");
            }

            System.IO.StreamWriter sw = null;
            strPath = Server.MapPath("~/bin/");
            strPathName = strPath + "\\ApplicationError.log";

            Application.Lock();

            try
            {
                sw = new System.IO.StreamWriter(strPathName, true, System.Text.Encoding.UTF8);
                sw.Write("Application Error:\r\n" + strErrorMessage.Replace("<br />", "\r\n") + "\r\n");
                sw.Close();
            }
            catch (Exception ex)
            {
                Response.Write("<br />" + ex.Message);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Dispose();
                    sw = null;
                }
            }

            Application.UnLock();
        }
开发者ID:husseinmuhammadi,项目名称:DSA,代码行数:47,代码来源:Global.asax.cs


注:本文中的System.IO.StreamWriter.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。