如何使用使用

编程入门 行业动态 更新时间:2024-10-16 00:19:05
本文介绍了如何使用使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Using来尝试插件可疑的内存泄漏。我已经开始使用dispose来实现它的所有东西,但没有 运气。我有几个关于使用的问题 我可以使用嵌套吗? 我使用它只适用于它作为 参数并没有帮助那些在使用块内变暗的参数。对吗? 我想在结束使用之前我仍然应该关闭并处理sql连接和 关闭文件等?

I''m looking at using Using to try an plug a suspected memory leak. I''ve already started using dispose for everything that implements it but no luck. I have several questions about Using Can I nest using? I take it using only applies to resources that it was given as parameters and will not help with those dimmed inside a using block. Right? I guess I''m still supposed to close and dispose sql connections and close files etc before end using?

推荐答案

你可以使用 进行嵌套你可以在连接,文件和流上使用 - 在任何东西上实现IDispose 。 HTH Alex " cj" < cj@nospam.nospamwrote in message news:ej ************** @ TK2MSFTNGP02.phx.gbl ... You can nest using You can use Using on connections, files and streams - on anything implementing IDispose. HTH Alex "cj" <cj@nospam.nospamwrote in message news:ej**************@TK2MSFTNGP02.phx.gbl... 我正在使用Using来尝试插件可疑的内存泄漏。我已经开始使用dispose来实现它的所有东西,但没有 运气。我有几个关于使用的问题 我可以使用嵌套吗? 我使用它只适用于作为参数给出的资源 并不会帮助那些在使用区域内变暗的人。对吗? 我想在结束使用之前我仍然应该关闭并处理sql连接并关闭 文件等? I''m looking at using Using to try an plug a suspected memory leak. I''ve already started using dispose for everything that implements it but no luck. I have several questions about Using Can I nest using? I take it using only applies to resources that it was given as parameters and will not help with those dimmed inside a using block. Right? I guess I''m still supposed to close and dispose sql connections and close files etc before end using?

所以在下面这段代码中我应该对sql适配器很好但是关于streamwriter的是什么 ?因为我在使用区域内调暗它是否 也保证要清理? 使用Sql2000DesktopDataAdapter作为新的 系统.Data.SqlClient.SqlDataAdapter(" select * from"& sourceTable, TextBox2.Text) 尝试 Sql2000DesktopDataAdapter.Fill(myds,0,10,sourceTable) Catch ex As Exception MessageBox.Show(" Error:"& ex.Message) 退出Sub 结束尝试 DataGridView1.DataSource = myds.Tables(sourceTable) Dim sw As New System.IO.StreamWriter(" C:\ test.txt",True) sw.WriteLine(" TESTING") sw.Close () 结束使用 或者我必须这样做吗? 使用Sql2000DesktopDataAdapter As New System.Data.SqlClient.SqlDataAdapter(" select * from"& sourceTable, TextBox2.Text),sw As New System.IO.StreamWriter(" C : \\ test.txt",True) 尝试 Sql2000DesktopDataAdapter.Fill(myds,0,10,sourceTable) Catch ex As Exception MessageBox.Show(" Error:" &安培; ex.Message) 退出Sub 结束尝试 DataGridView1.DataSource = myds.Tables(sourceTable) sw.WriteLine(" TESTING") sw.Close() 结束使用 cj写道: So in this code below I should be good with the sql adapter but what about the streamwriter? Since I dimmed it inside the using block is it guaranteed to be cleaned up too? Using Sql2000DesktopDataAdapter As New System.Data.SqlClient.SqlDataAdapter("select * from " & sourceTable, TextBox2.Text) Try Sql2000DesktopDataAdapter.Fill(myds, 0, 10, sourceTable) Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Exit Sub End Try DataGridView1.DataSource = myds.Tables(sourceTable) Dim sw As New System.IO.StreamWriter("C:\test.txt", True) sw.WriteLine("TESTING") sw.Close() End Using Or do I have to do this? Using Sql2000DesktopDataAdapter As New System.Data.SqlClient.SqlDataAdapter("select * from " & sourceTable, TextBox2.Text), sw As New System.IO.StreamWriter("C:\test.txt", True) Try Sql2000DesktopDataAdapter.Fill(myds, 0, 10, sourceTable) Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Exit Sub End Try DataGridView1.DataSource = myds.Tables(sourceTable) sw.WriteLine("TESTING") sw.Close() End Using cj wrote: 我正在使用Using来尝试插件可疑的内存泄漏。我已经开始使用dispose来实现它的所有东西,但没有 运气。我有几个关于使用的问题 我可以使用嵌套吗? 我使用它只适用于它作为 参数并没有帮助那些在使用区域内变暗的东西。 对吗? 我想我仍然应该在结束使用之前关闭并配置sql连接和 关闭文件等? I''m looking at using Using to try an plug a suspected memory leak. I''ve already started using dispose for everything that implements it but no luck. I have several questions about Using Can I nest using? I take it using only applies to resources that it was given as parameters and will not help with those dimmed inside a using block. Right? I guess I''m still supposed to close and dispose sql connections and close files etc before end using?

cj, 你怎么知道你有内存泄漏。请不要告诉我你已经在任务管理器中看到了这一点,一看谷歌就会给你 响应的答案,但没有说明。 Cor " cj" < cj@nospam.nospamschreef in bericht news:%2 **************** @ TK2MSFTNGP06.phx.gbl ... cj, How do you know that you have a memory leak. And please don''t tell me that you have seen that in the taskmanager, one look at Google gives you thousends of responses that that says nothing. Cor "cj" <cj@nospam.nospamschreef in bericht news:%2****************@TK2MSFTNGP06.phx.gbl... 所以在下面这段代码中,我应该对sql适配器很好,但是什么关于 的算盘?因为我在使用区域内调暗它是否 也保证要清理? 使用Sql2000DesktopDataAdapter作为新的 系统.Data.SqlClient.SqlDataAdapter(" select * from"& sourceTable, TextBox2.Text) 尝试 Sql2000DesktopDataAdapter.Fill(myds,0,10,sourceTable) Catch ex As Exception MessageBox.Show(" Error:"& ex.Message) 退出Sub 结束尝试 DataGridView1.DataSource = myds.Tables(sourceTable) Dim sw As New System.IO.StreamWriter(" C:\ test.txt",True) sw.WriteLine(" TESTING") sw.Close () 结束使用 或者我必须这样做吗? 使用Sql2000DesktopDataAdapter As New S. ystem.Data.SqlClient.SqlDataAdapter(" select * from" &安培; sourceTable, TextBox2.Text),sw As New System.IO.StreamWriter(" C:\ test.txt",True) 试试 Sql2000DesktopDataAdapter.Fill(myds,0,10,sourceTable) Catch ex As Exception MessageBox.Show(" Error:" & ex.Message) 退出Sub 结束尝试 DataGridView1.DataSource = myds.Tables(sourceTable) sw.WriteLine(" TESTING") sw.Close() 结束使用 cj写道: So in this code below I should be good with the sql adapter but what about the streamwriter? Since I dimmed it inside the using block is it guaranteed to be cleaned up too? Using Sql2000DesktopDataAdapter As New System.Data.SqlClient.SqlDataAdapter("select * from " & sourceTable, TextBox2.Text) Try Sql2000DesktopDataAdapter.Fill(myds, 0, 10, sourceTable) Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Exit Sub End Try DataGridView1.DataSource = myds.Tables(sourceTable) Dim sw As New System.IO.StreamWriter("C:\test.txt", True) sw.WriteLine("TESTING") sw.Close() End Using Or do I have to do this? Using Sql2000DesktopDataAdapter As New System.Data.SqlClient.SqlDataAdapter("select * from " & sourceTable, TextBox2.Text), sw As New System.IO.StreamWriter("C:\test.txt", True) Try Sql2000DesktopDataAdapter.Fill(myds, 0, 10, sourceTable) Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Exit Sub End Try DataGridView1.DataSource = myds.Tables(sourceTable) sw.WriteLine("TESTING") sw.Close() End Using cj wrote: >我正在使用Using来尝试插件可疑的内存泄漏。我已经开始使用dispose来实现它的所有功能但没有运气。我有几个关于使用的问题 我可以使用嵌套吗? 我使用它只适用于作为参数给出的资源并且无法帮助那些在使用区域内变暗的。对吗? 我想在结束使用之前我仍然应该关闭并处理sql连接并关闭文件等? >I''m looking at using Using to try an plug a suspected memory leak. I''vealready started using dispose for everything that implements it but noluck. I have several questions about UsingCan I nest using?I take it using only applies to resources that it was given as parametersand will not help with those dimmed inside a using block. Right?I guess I''m still supposed to close and dispose sql connections and closefiles etc before end using?

更多推荐

如何使用使用

本文发布于:2023-06-01 03:18:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/405132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!