/// <summary> /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component"/> and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (v2TaskService != null) { try { Marshal.ReleaseComObject(v2TaskService); } catch { } v2TaskService = null; } if (v1TaskScheduler != null) { try { Marshal.ReleaseComObject(v1TaskScheduler); } catch { } v1TaskScheduler = null; } if (v1Impersonation != null) { v1Impersonation.Dispose(); v1Impersonation = null; } base.Dispose(disposing); }
/// <summary> /// Releases all resources used by this class. /// </summary> public void Dispose() { v1TS = null; v2Svc = null; if (v2Coll != null) { Marshal.ReleaseComObject(v2Coll); } }
internal static V2Interop.IRegisteredTask GetTask([NotNull] V2Interop.ITaskService iSvc, [NotNull] string name) { V2Interop.ITaskFolder fld = null; try { fld = iSvc.GetFolder("\\"); return(fld.GetTask(name)); } catch { return(null); } finally { if (fld != null) { Marshal.ReleaseComObject(fld); } } }
/// <summary> /// Releases all resources used by this class. /// </summary> public void Dispose() { v2Svc = null; iEnum = null; }
internal RunningTaskEnumerator(TaskService svc, V2Interop.IRunningTaskCollection iTaskColl) { this.svc = svc; v2Svc = svc.v2TaskService; iEnum = iTaskColl.GetEnumerator(); }
internal RunningTaskCollection(TaskService svc, V2Interop.IRunningTaskCollection iTaskColl) { this.svc = svc; v2Svc = svc.v2TaskService; v2Coll = iTaskColl; }
/// <summary> /// Connects this instance of the <see cref="TaskService"/> class to a running Task Scheduler. /// </summary> private void Connect() { ResetUnsetProperties(); if (!initializing && !DesignMode) { if (((!string.IsNullOrEmpty(userDomain) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPassword)) || (string.IsNullOrEmpty(userDomain) && string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userPassword)))) { // Clear stuff if already connected Dispose(true); if (hasV2 && !forceV1) { v2TaskService = new V2Interop.ITaskService(); if (!string.IsNullOrEmpty(targetServer)) { // Check to ensure character only server name. (Suggested by bigsan) if (targetServer.StartsWith(@"\")) { targetServer = targetServer.TrimStart('\\'); } // Make sure null is provided for local machine to compensate for a native library oddity (Found by ctrollen) if (targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase)) { targetServer = null; } } else { targetServer = null; } v2TaskService.Connect(targetServer, userName, userDomain, userPassword); targetServer = v2TaskService.TargetServer; userName = v2TaskService.ConnectedUser; userDomain = v2TaskService.ConnectedDomain; maxVer = GetV2Version(); } else { v1Impersonation = new WindowsImpersonatedIdentity(userName, userDomain, userPassword); v1TaskScheduler = new V1Interop.ITaskScheduler(); if (!string.IsNullOrEmpty(targetServer)) { // Check to ensure UNC format for server name. (Suggested by bigsan) if (!targetServer.StartsWith(@"\\")) { targetServer = @"\\" + targetServer; } } else { targetServer = null; } v1TaskScheduler.SetTargetComputer(targetServer); targetServer = v1TaskScheduler.GetTargetComputer(); maxVer = v1Ver; } } else { throw new ArgumentException("A username, password, and domain must be provided."); } } }