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


C# StreamWriter.Dispose方法代码示例

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


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

示例1: CommitQuizAnswers

        private static void CommitQuizAnswers(String quizAnswers, String personName, String setupID)
        {
            XmlSerializer writer;
            StreamWriter quizAnswersFile = null;
            DataSet quizData = null;
            try
            {
                if (String.IsNullOrEmpty(quizAnswers))
                    return;

                quizData = RetrieveQuizAnswersData();

                //Create the dataset of answers
                quizData.Tables[0].Rows.Add(setupID, personName, quizAnswers, DateTime.Now);

                writer = new XmlSerializer(typeof(DataSet));
                quizAnswersFile = new StreamWriter(QuizAnswersFilePath);
                writer.Serialize(quizAnswersFile, quizData);
                quizAnswersFile.Close();
                quizAnswersFile.Dispose();
            }
            catch (Exception ex)
            {
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in CommitQuizAnswers at Screen side {0}", ex.Message);
                writer = null;
                if (quizAnswersFile != null)
                {
                    quizAnswersFile.Close();
                    quizAnswersFile.Dispose();
                }
            }
        }
开发者ID:guozanhua,项目名称:kinect-ripple,代码行数:32,代码来源:QuizAnswersWriter.cs

示例2: CommitTelemetry

        public static void CommitTelemetry()
        {
            XmlSerializer writer;
            StreamWriter telemetryFile = null;
            try
            {
                if (telemetryData == null)
                    return;

                writer = new XmlSerializer(typeof(DataSet));
                telemetryFile = new StreamWriter(TelemetryFilePath);
                writer.Serialize(telemetryFile, telemetryData);
                telemetryFile.Close();
                telemetryFile.Dispose();
                telemetryData = null;
            }
            catch (Exception ex)
            {
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in CommitTelemetry at Screen side {0}", ex.Message);
                writer = null;
                if (telemetryFile != null)
                {
                    telemetryFile.Close();
                    telemetryFile.Dispose();
                }
                telemetryData = null;
            }
        }
开发者ID:guozanhua,项目名称:kinect-ripple,代码行数:28,代码来源:TelemetryWriter.cs

示例3: WriteToFile

 /// <summary>
 /// Writes entries to the data file
 /// </summary>
 /// <param name="employeeList">List of employee objects to be written</param>
 public void WriteToFile(List<Employee> employeeList)
 {
     StreamWriter writer = null;
     try
     {
         writer = new StreamWriter(fileName);
         writer.Write(JsonConvert.SerializeObject(employeeList));
     }
     catch (JsonSerializationException)
     {
         throw new JsonSerializationException();
     }
     catch (IOException)
     {
         throw new IOException();
     }
     catch(NotSupportedException)
     {
         throw new NotSupportedException();
     }
     finally
     {
         if (writer != null)
             writer.Dispose();
     }
 }
开发者ID:amolr,项目名称:CRUDRestAPI,代码行数:30,代码来源:FileWriter.cs

示例4: Save

		public static void Save( Player p ) {
			StreamWriter sw = new StreamWriter( File.Create( "players/" + p.name + "DB.txt" ) );
			sw.WriteLine ("Nick = " + p.DisplayName );
			sw.Flush();
			sw.Close();
			sw.Dispose();
		}
开发者ID:tommyz56,项目名称:MCGalaxy,代码行数:7,代码来源:PlayerDB.cs

示例5: log_write

        public static void log_write(string str, string reason, string logname)
        {
            string EntryTime = DateTime.Now.ToLongTimeString();
            string EntryDate = DateTime.Today.ToShortDateString();
            string fileName = "log/" + logname + ".log";  //log + data +logname ?

            if (!Directory.Exists(Environment.CurrentDirectory + "/log/"))
            {
                Directory.CreateDirectory((Environment.CurrentDirectory + "/log/"));
            }

            try
            {
                StreamWriter sw = new StreamWriter(fileName, true, System.Text.Encoding.UTF8);
                sw.WriteLine("[" + EntryDate + "][" + EntryTime + "][" + reason + "]" + " " + str);
                sw.Close();
                //check this
                sw.Dispose();
            }
            catch (Exception ex)
            {
                log_write(ex.Message, "Exception", "Exception");
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:partizanes,项目名称:Check_action,代码行数:25,代码来源:Log.cs

示例6: WriteLog

        /// <summary>
        /// �ڱ���д�������־
        /// </summary>
        /// <param name="exception"></param> 
        public static void WriteLog(string debugstr)
        {
            lock (writeFile)
            {
                FileStream fs = null;
                StreamWriter sw = null;

                try
                {
                    string filename = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                    //����������־Ŀ¼
                    string folder = HttpContext.Current.Server.MapPath("~/Log");
                    if (!Directory.Exists(folder))
                        Directory.CreateDirectory(folder);
                    fs = new FileStream(folder + "/" + filename, System.IO.FileMode.Append, System.IO.FileAccess.Write);
                    sw = new StreamWriter(fs, Encoding.UTF8);
                    sw.WriteLine( DateTime.Now.ToString() + "     " + debugstr + "\r\n");
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Flush();
                        sw.Dispose();
                        sw = null;
                    }
                    if (fs != null)
                    {
                        //     fs.Flush();
                        fs.Dispose();
                        fs = null;
                    }
                }
            }
        }
开发者ID:BlueFisher,项目名称:OrderSystem,代码行数:39,代码来源:LogUtil.cs

示例7: Post

        public void Post(UserSocialConnection ConnectionData, string Update)
        {
            try
            {
                string apiCallUrl = String.Format("https://graph.facebook.com/me/feed"); // Format the call string
                HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(apiCallUrl);
                wr.Method = "POST";
                wr.ContentType = "application/x-www-form-urlencoded";

                string data = "access_token=" + ConnectionData.Token + "&message=" + HttpUtility.UrlEncode(Update);
                wr.ContentLength = data.Length;
                StreamWriter sw = new StreamWriter(wr.GetRequestStream());
                sw.Write(data);
                sw.Close();

                StreamReader sr = new StreamReader(wr.GetResponse().GetResponseStream());
                string jsonResponse = sr.ReadToEnd();

                sr.Close();

                sw.Dispose();
                sr.Dispose();

                if (jsonResponse.Contains("\"error_code\"")) // Proces the response for errors - a simple throw is used to convert the text error in to an exception
                    throw new Exception(String.Format("Error calling facebook API!\nJSON: {0} \nAPI CALL: {1}", jsonResponse, apiCallUrl));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in FacebookSocialConnector.Post processing User ID #" + ConnectionData.UserId + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
开发者ID:bscarlavai,项目名称:social-gamer,代码行数:31,代码来源:FacebookSocialConnector.cs

示例8: WriteLog

        /// <summary>
        ///  日志记录
        /// </summary>
        /// <param name="message">要写入消息</param>
        /// <param name="path">文件路径:C:\\Log.txt</param>
        public static void WriteLog(string message, LogFile logFile)
        {
            string pathFile = null;
            switch (logFile)
            {
                case LogFile.GetProxyIP:
                    pathFile = "C:\\GreamGugGetProxyIP.txt";
                    break;
                case LogFile.SetIE:
                    pathFile = "C:\\GreamGugProxies.txt";
                    break;
                case LogFile.ValidateProxy:
                    pathFile = "C:\\GreamGugValidateProxy.txt";
                    break;
                default:
                    pathFile = "C:\\GreamGugLog.txt";
                    break;
            }
            try
            {

                StreamWriter sw = new StreamWriter(pathFile, true, Encoding.UTF8);
                sw.WriteLine("{0} ---{1}", DateTime.Now.ToLongDateString(), message);
                sw.Close();
                sw.Dispose();
            }
            catch (IOException ex)
            {
                return;
            }
        }
开发者ID:tianmaoyu,项目名称:DreamGun,代码行数:36,代码来源:Log.cs

示例9: okBtn_Click

        private void okBtn_Click(object sender, EventArgs e)
        {
            try
            {
                File.Delete(setup.viewprefs);
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(setup.viewprefs))
                {
                    if (explorerBox.Checked == true)
                        sw.WriteLine("true");
                    else sw.WriteLine("false");

                    if (statusBox.Checked == true)
                        sw.WriteLine("true");
                    else sw.WriteLine("false");

                    if (debuggingBox.Checked == true)
                        sw.WriteLine("true");
                    else sw.WriteLine("false");

                    if (lnBox.Checked)
                        sw.WriteLine("true");
                    else sw.WriteLine("false");

                    sw.Dispose();
                }
            }

            catch
            {
                MessageBox.Show("Could not save preferences.\nDefault values have been saved instead.",
                "Scale", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            this.Close();
        }
开发者ID:kryptonX,项目名称:Scale,代码行数:35,代码来源:vpreface.cs

示例10: Main

        private static void Main(string[] args)
        {
            StreamReader reader = new StreamReader("../../wordFile.txt");
             StreamReader readerSearchFile = new StreamReader("../../textFile.txt");
             StreamWriter writer = new StreamWriter("../../resultFile.txt");
            try
            {

                SortedDictionary<String, int> words = new SortedDictionary<string, int>();
                string word = reader.ReadLine();
                string textFile = readerSearchFile.ReadToEnd().ToLower();
                while (word != null)
                {
                    word = word.ToLower();

                    string pattern = @"\b" + word + @"\b";
                    MatchCollection matches = Regex.Matches(textFile, pattern);
                    words.Add(word, matches.Count);
                    word = reader.ReadLine();

                }
                var ordered = words.OrderByDescending(pair => pair.Value);
                foreach (KeyValuePair<string, int> pair in ordered)
                {
                    writer.WriteLine("{0} - {1}", pair.Key, pair.Value);
                }
            }
            finally
            {
                writer.Flush();
                reader.Dispose();
                readerSearchFile.Dispose();
                writer.Dispose();
            }
        }
开发者ID:exploitx3,项目名称:C-Sharp-,代码行数:35,代码来源:Word+Count.cs

示例11: FileWrite

 static void FileWrite(string contents, int lineNumber)
 {
     StreamWriter writeToFile = new StreamWriter("..\\..\\testresult.txt", true, Encoding.GetEncoding("windows-1251"));
     writeToFile.Write("{0}.", lineNumber);
     writeToFile.WriteLine(contents);
     writeToFile.Dispose();
 }
开发者ID:stoyans,项目名称:Telerik,代码行数:7,代码来源:InsertLineNumbers.cs

示例12: ReadFromStreamWithDefaultColumnsShouldHandleFirstRowAsRowData

        public void ReadFromStreamWithDefaultColumnsShouldHandleFirstRowAsRowData()
        {
            DataTableBuilder builder = new DataTableBuilder();
            var stream = new MemoryStream();
            var sw = new StreamWriter(stream);
            var rows = new[] { "first,row,is,data", "second,row,is,johnny", "second,row,was,laura", };
            foreach (var row in rows)
            {
                sw.WriteLine(row);
            }

            sw.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            try
            {
                var lazy = builder.ReadLazy(stream, rows[0].Split(','));
                Assert.Equal(rows[0].Split(','), lazy.ColumnNames);
                var rowEnumerator = rows.Skip(0).GetEnumerator();
                rowEnumerator.MoveNext();
                var rowCount = 0;
                foreach (var row in lazy.Rows)
                {
                    Assert.Equal(rowEnumerator.Current, string.Join(",", row.Values));
                    rowEnumerator.MoveNext();
                    rowCount++;
                }

                Assert.Equal(rows.Length, rowCount);
            }
            finally
            {
                sw.Dispose();
                stream.Dispose();
            }
        }
开发者ID:aaronhoffman,项目名称:DataTable,代码行数:35,代码来源:ReaderTests.cs

示例13: Write

		private void Write(string fileName, Player player)
		{
			string winners = $"{player.name}, {player.won}";
			using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
			using (StreamWriter sw = new StreamWriter(fs))
			{ sw.WriteLine(winners); sw.Dispose(); }
		}
开发者ID:gwenhidwy,项目名称:RockPaperScissors,代码行数:7,代码来源:FileWriter.cs

示例14: LoadLanguage

 /// <summary>
 /// Load a Language using the project resources, depending on the settings.
 /// </summary>
 internal void LoadLanguage()
 {
     XmlSerializer serializer = new XmlSerializer(_currentLanguage.GetType());
     using (MemoryStream stream = new MemoryStream())
     {
         StreamWriter writer = new StreamWriter(stream);
         string res;
         switch (Properties.Settings.Default.Language)
         {
             case 0:
                 res = Properties.Resources.nl;
                 break;
             case 1:
                 res = Properties.Resources.eng;
                 break;
             case 2:
                 res = Properties.Resources.ita;
                 break;
             case 3:
                 res = Properties.Resources.pl;
                 break;
             case 4:
                 res = Properties.Resources.tr;
                 break;
             default:
                 res = Properties.Resources.eng;
                 break;
         }
         writer.Write(res);
         writer.Flush();
         stream.Position = 0;
         _currentLanguage = (Language)serializer.Deserialize(stream);
         writer.Dispose();
     }
 }
开发者ID:campbeb,项目名称:DeadLock,代码行数:38,代码来源:LanguageManager.cs

示例15: Create

 public static void Create(string path, string content)
 {
     FileStream fs = null;
     StreamWriter sw = null;
     try
     {
         fs = File.Create(path);
         sw = new StreamWriter(fs);
         sw.Write(content);
         sw.Flush();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (sw != null)
         {
             sw.Dispose();
         }
         if (fs != null)
         {
             fs.Dispose();
         }
     }
 }
开发者ID:dalinhuang,项目名称:tdcodes,代码行数:27,代码来源:FileUtility.cs


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