Idle Client not showing in Open Task view any more.
2 // Copyright (C) 2014-2016 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
22 using System.ComponentModel;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
29 using System.Diagnostics;
30 using SharpLib.Display;
33 namespace SharpDisplayIdleClient
37 /// Sharp Display Client designed to act as an idle client.
38 /// It should take care of screen saving and other such concerns.
40 public partial class FormClientIdle : Form
42 public StartParams Params { get; set; }
45 ContentAlignment iAlignment;
48 public delegate void CloseDelegate();
49 public delegate void CloseConnectionDelegate();
52 public FormClientIdle()
54 InitializeComponent();
60 /// <param name="sender"></param>
61 /// <param name="e"></param>
62 private void FormClientIdle_Load(object sender, EventArgs e)
64 //Prevents showing in the Open Task view (Windows Key + Tab)
68 iClient = new Client();
69 iClient.CloseOrderEvent += OnCloseOrder;
71 iClient.SetName("Idle");
72 iClient.SetPriority(Priorities.Background);
76 iTimer.Interval = IntervalToNextMinute();
83 /// <returns></returns>
84 public static int IntervalToNextMinute()
86 DateTime now = DateTime.Now;
87 return 60000 - now.Millisecond;
94 /// <returns></returns>
95 public bool IsClientReady()
97 return (iClient != null && iClient.IsReady());
103 public void SetupDisplayClient()
107 //Set one column one line layout
108 TableLayout layout = new TableLayout(1, 1);
109 iClient.SetLayout(layout);
112 iAlignment = ContentAlignment.MiddleCenter;
113 iTextField = new TextField(DateTime.Now.ToString("t"), iAlignment, 0, 0);
116 iClient.CreateFields(new DataField[]
122 public void OnCloseOrder()
130 public void CloseThreadSafe()
132 if (this.InvokeRequired)
134 //Not in the proper thread, invoke ourselves
135 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
136 this.Invoke(d, new object[] { });
140 //We are in the proper thread
148 public void CloseConnectionThreadSafe()
150 if (this.InvokeRequired)
152 //Not in the proper thread, invoke ourselves
153 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
154 this.Invoke(d, new object[] { });
158 //We are in the proper thread
161 string sessionId = iClient.SessionId;
162 Trace.TraceInformation("Closing client: " + sessionId);
164 Trace.TraceInformation("Closed client: " + sessionId);
174 /// <param name="sender"></param>
175 /// <param name="e"></param>
176 private void FormClientIdle_FormClosing(object sender, FormClosingEventArgs e)
178 CloseConnectionThreadSafe();
185 /// <param name="sender"></param>
186 /// <param name="e"></param>
187 private void iTimer_Tick(object sender, EventArgs e)
190 iTimer.Interval = IntervalToNextMinute();
194 if (String.IsNullOrEmpty(iTextField.Text))
196 //Time to show our time
197 iTextField.Text = DateTime.Now.ToString("t");
201 //Do some screen saving
202 iTextField.Text = "";
206 iClient.SetField(iTextField);
208 //Now make sure we save our screen from any running system monitor
209 if (String.IsNullOrEmpty(iTextField.Text))
211 //If text it empty it means we need to cool down our display even if system monitor is running
212 iClient.SetPriority(Priorities.SystemMonitor + 1);
216 //Switch back to background then, leaving system monitor if any doing its magic
217 iClient.SetPriority(Priorities.Background);
221 private void FormClientIdle_Shown(object sender, EventArgs e)