예제 #1
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            client = new WlanClient();
            //Miofile = "C:\\" + DateTime.Now.ToLongDateString() + "-" +DateTime.Now.ToShortTimeString() + "_catture.txt";
            //System.IO.File.AppendAllText("c:\\catture.txt", "PARTOOOOOOOOOOOOOOOOOOOOO\r\n");

            // Initialize data structure
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = default_interval;
            //System.IO.File.AppendAllText("c:\\catture.txt", "PARTOOOOOOOOOOOOOOOOOOOOO\r\n");

            //initialize the mutex
            mut = new Mutex(false,"Global\\ServiceMutex");
            MutexSecurity mSec = mut.GetAccessControl();
            var rule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                               MutexRights.Modify
                                | MutexRights.Synchronize
                                | MutexRights.TakeOwnership
                                | MutexRights.ReadPermissions,
                               AccessControlType.Allow);
            mSec.AddAccessRule(rule);
            mut.SetAccessControl(mSec);
            // Set the time interval

            //System.IO.File.AppendAllText("c:\\catture.txt", "PARTOOOOOOOOOOOOOOOOOOOOO\r\n");
            // File Mapping creation
            try
            {
                mmf = MemoryMappedFile.CreateNew("Global\\Broadcast", MappedFileDimension, MemoryMappedFileAccess.ReadWrite);
            }
            catch (Exception e)
            {
                System.IO.File.AppendAllText("c:\\catture.txt", e.ToString());
            }
            var mmfSec = mmf.GetAccessControl();
            mmfSec.SetAccessRule(new AccessRule<MemoryMappedFileRights>(new SecurityIdentifier(WellKnownSidType.WorldSid, null),MemoryMappedFileRights.FullControl | MemoryMappedFileRights.Read, AccessControlType.Allow));
            mmf.SetAccessControl(mmfSec);
            //System.IO.File.AppendAllText("c:\\catture.txt", "PARTOOOOOOOOOOOOOOOOOOOOO\r\n");
            stream = mmf.CreateViewStream(0, MappedFileDimension, MemoryMappedFileAccess.ReadWrite);
            //System.IO.File.AppendAllText("c:\\catture.txt", "FINISCO PARTENZA\r\n");

            aTimer.Enabled = true;
        }