コード例 #1
0
        static void SDMountThread()
        {
            SDCard    SD        = null;
            const int POLL_TIME = 500; // check every 500 millisecond

            bool sdExists;

            while (true)
            {
                try // If SD card was removed while mounting, it may throw exceptions
                {
                    sdExists = !sdCardDetect.Read();

                    // make sure it is fully inserted and stable
                    if (sdExists)
                    {
                        Thread.Sleep(50);
                        sdExists = !sdCardDetect.Read();
                    }

                    if (sdExists && SD == null)
                    {
                        SD = new SDCard();
                        SD.Mount();
                    }
                    else if (!sdExists && SD != null)
                    {
                        SD.Unmount();
                        SD.Dispose();
                        SD = null;
                    }
                    else if (sdExists && SD != null)
                    {
                        if (sdCardWriteProtect.Read() == true)
                        {
                            ReadyWrite = false;
                            //Debug.Print("ReadyWrite: false");
                        }
                        else
                        {
                            ReadyWrite = true;
                            //Debug.Print("ReadyWrite: true. Flushing!");
                            volume_info.FlushAll();
                        }
                    }
                }
                catch
                {
                    if (SD != null)
                    {
                        SD.Dispose();
                        SD = null;
                    }
                }

                Thread.Sleep(POLL_TIME);
            }
        }
コード例 #2
0
ファイル: ServiceDiscovery.cs プロジェクト: arition/SmartHome
 public void Dispose()
 {
     MDNS?.Dispose();
     SD?.Dispose();
 }