小编mou*_*kin的帖子

如何删除为普通I/O打开的文件?

如何删除为普通I/O打开的文件?

我想解密文件.如果代码不正确,那么我需要删除输出文件.

我不能用,File.Delete()因为:

Windows NT 4.0平台注意:删除不会删除为普通I/O打开的文件或内存映射的文件.

try
{
    FileStream fsIn = new FileStream(fileIn, FileMode.Open, FileAccess.Read, FileShare.Delete);
    FileStream fsOut = new FileStream(fileOut, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Delete);

    PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
    Rijndael alg = Rijndael.Create();

    alg.Key = pdb.GetBytes(32);
    alg.IV = pdb.GetBytes(16);

    CryptoStream cs = new CryptoStream(fsOut, alg.CreateDecryptor(), CryptoStreamMode.Write);

    int bufferLen = 4096;
    byte[] buffer = new byte[bufferLen];
    int bytesRead;

    do
    {
        bytesRead = fsIn.Read(buffer, 0, …
Run Code Online (Sandbox Code Playgroud)

c# stream

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

定时器被中断

我在Windows窗体应用程序中的Timer有问题.需要Timer记录归档时间的归档程序.然而有什么东西打断了计时器?

我怀疑是流.关于什么可能导致计时器中断的任何建议?

public partial class Form1 : Form
{
    int timerCounter = 0;
    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

    public Form1()
    {
        InitializeComponent();
        timer.Interval = 1000; 
        timer.Enabled = true;
    }

    public void button2_Click(object sender, EventArgs e)
    {
        timer.Start();
        timer.Tick += new EventHandler(timer1_Tick); 

        // code for archiving, streams

        timer.Stop(); 

        MessageBox.Show("Archive was created! :)");
    }

    public void timer1_Tick(object sender, EventArgs e)
    {
        this.label7.Text = (++timerCounter).ToString();
    }  
Run Code Online (Sandbox Code Playgroud)

}

.net c# timer stream

-2
推荐指数
1
解决办法
290
查看次数

标签 统计

c# ×2

stream ×2

.net ×1

timer ×1