小编Nic*_*rez的帖子

有没有人使用.NET的System.IO.IsolatedStorage?

我正在阅读.NET中的System.IO.IsolatedStorage命名空间,发现我可以使用它将文件存储到我的程序集或可执行文件的唯一位置.例如,以下代码:

using System.IO.IsolatedStorage;

public class Program
{
     static void Main(string[] args)
     {
           IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
           store.CreateFile("myUserFile.txt");
     }
 }
Run Code Online (Sandbox Code Playgroud)

在以下位置创建文件"myUserFile.txt":

C:\用户\尼克\应用程序数据\本地\ IsolatedStorage\bhxcjtkp.bpv\wbjkcolm.3br\StrongName.m2s0saaun2onmow3pd5pkml30lf2dobr\AssemFiles

并使用IsolatedStorageFile.GetMachineStoreForAssembly()在C:\ ProgramData\IsolatedStorage下创建类似的目录结构.

我可以看到让这个API为您创建存储位置的好处(不必自己想出文件路径).但我很惊讶地看到,其他第三方应用程序(至少不在我的计算机上)没有任何其他文件存储在IsolatedStorage中.

相反,我发现了很多程序存储配置文件,只需在C:\ Users\Nick\AppData\Local下.有谁知道软件供应商可能会回避使用IsolatedStorage的原因?或者他们是否使用不同的API来存储AppData下的文件?

.net c# isolatedstorage

10
推荐指数
1
解决办法
3880
查看次数

C# - 要关闭NetworkStream,请调用stream.Close或socket.Shutdown?

我想知道是否有人知道处理使用Socket对象和NetworkStream对象的类的最佳方法?有问题的类有一个NetworkStream实例和一个用于创建NetworkStream的Socket实例.

this.socket = new Socket(
                           AddressFamily.InterNetwork,
                           SocketType.Stream,
                           ProtocolType.Tcp)
                        {
                            ReceiveBufferSize = 65536,
                            SendBufferSize = 150
                        };

this.socket.Connect(
                        new IPEndPoint(                                                                   
                              IPAddress.Parse(
                                          Properties.Settings.Default.MpsServer2),
                                          Properties.Settings.Default.MpsPort2));

this.stream = new NetworkStream(
                         this.socket, true);
Run Code Online (Sandbox Code Playgroud)

在我的Dispose方法中,我应该这样做吗?

this.stream.Close();
this.socket.Shutdown(SocketShutdown.Both);
this.socket.Close();
Run Code Online (Sandbox Code Playgroud)

所有这些都是必要的还是过度杀伤?

c# sockets networkstream stream

9
推荐指数
1
解决办法
6952
查看次数

标签 统计

c# ×2

.net ×1

isolatedstorage ×1

networkstream ×1

sockets ×1

stream ×1