⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filemutex.cs

📁 PDA程序PDA for windows CE take a look
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;

namespace GasPDA
{
    public class FileMutex
    {
        private FileStream aFile;

        public FileMutex()
        {
        }

        public bool Open()
        {
            string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
            string strFile = strAppDir + @"\Log.txt";

            try
            {
                aFile = new FileStream(strFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            }
            catch
            {
                return false;
            }

            return true;
        }

        public void Dispose()
        {
            try
            {
                aFile.Close();
                aFile = null;
            }
            catch
            {
                //Console.WriteLine("自动释放资源失败!");
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -