コード例 #1
0
        public void ReloadScript()
        {
            var initialTargetVersion = targetVersion;

            int localCurrentVersion;

            do
            {
                localCurrentVersion = currentVersion;
                if (targetVersion <= localCurrentVersion)
                {
                    targetVersion = localCurrentVersion + 1;
                }
            }while (currentVersion != localCurrentVersion);

            if (targetVersion > initialTargetVersion)
            {
                OnScriptChanged?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #2
0
        void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            //PowerGUI fires the change event twice. To avoid crashes ignores the first change event.
            changeCounter++;
            if (changeCounter % 2 == 0)
            {
                try
                {
                    this.Script = File.ReadAllText(scriptPath, Encoding.UTF8);

                    if (OnScriptChanged != null)
                    {
                        OnScriptChanged.GetType().InvokeMember("", BindingFlags.InvokeMethod, null, OnScriptChanged, new object[] { this, Script });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }