The second system tray notification is not shown In windows 7/8/8.1 in a C# application

  • Thread starter Thread starter Sagar R. Kapadia
  • Start date Start date
S

Sagar R. Kapadia

Guest
I have an C# application which shows two system tray notifications, one at the beginning of a long process and one at the end. In windows 7/8/8.1 the second notification does not appear, even though the time interval between the notification is of the order of a couple of minutes. How can I resolve this issue?.

The code is as follows

public class BizBrainAgentCacheLoaderApp : ApplicationContext

{

//App Constructor, called from Main in Program.cs
public BizBrainAgentCacheLoaderApp(bool askPermission)
{

logger = new Logger("BizBrainAgentCacheLoaderApp");
logger.Log("BizBrainAgentCacheLoaderApp ctor:AskPermission?"+askPermission);
try
{

logger.Log("Before Initialize");
bool isAdmin = IsUserAnAdmin();

//Perform Initialization
Initialize();

logger.Log("After Initialize");
}
catch(Exception e)
{
logger.Log("Initialize Exception:" + e.Message);
logger.Log(e.StackTrace);
Application.Exit();
}
if (initialized)
{
if (askPermission && PermissionDenied())
{
return;
}
//Show the System Tray Icon and Notification
StartProcess();
try
{
//Lengthy Process before and after which notification is shown
LoadCache();

}
catch (Exception e)
{
MessageBox.Show(e.Message);
MessageBox.Show(e.StackTrace);
logger.Log("SetIcon:" + e.Message);


}
finally
{
//Hide the System Tray Icon and Notification
StopProcess();
}
}
else
{
MessageBox.Show("Failed to Initialize! Shutting down");
logger.Fatal("Failed to Initialize! Shutting down");
}


}
//Calls a web api and shows the 'started' notification
private void StartProcess()
{
clientId = Server.GetAgentInfo().ClientId;


SetRunningIcon();
string uriFragment = "updateCachingFlag?";
string uri = uriFragment + "clientId=" + clientId + "&state=0";
try
{
apiClient.ExecuteGet(uri);
}
catch (Exception e)
{
logger.Error("Exception in updating caching flag:" + e.Message);
logger.Error(e.StackTrace);
}

}
//Calls a web api and shows the 'finished' notification
private void StopProcess()
{
string uriFragment = "updateCachingFlag?";
string uri = uriFragment + "clientId=" + clientId + "&state=1";
try
{
apiClient.ExecuteGet(uri);
}
catch (Exception e)
{
logger.Error("Exception in updating caching flag:" + e.Message);
logger.Error(e.StackTrace);
}
SetFinishedIcon();

Shutdown();

}
//Instantiate the NotifyIcon
void CreateNotifyIcon()
{
if (trayIcon == null)
{
trayIcon = new NotifyIcon()
{
Icon = BizBrain_CacheLoader.Properties.Resources.Tally,
ContextMenu = new ContextMenu(new MenuItem[] {
new MenuItem("Info",Info)


}),
Visible = true
};
trayIcon.Text = "BizBrain Agent Cache Loader";
trayIcon.Click += TrayIcon_Click;
}
}
//Show Running Notification
void SetRunningIcon()
{

try {
CreateNotifyIcon();
trayIcon.Icon = BizBrain_CacheLoader.Properties.Resources.Tally;
trayIcon.Text = "Loading Cache";
trayIcon.BalloonTipTitle = "BizBrain Agent Cache Loader";
trayIcon.BalloonTipText = "Caching Started";
trayIcon.BalloonTipIcon = ToolTipIcon.Info;
trayIcon.ShowBalloonTip(5000);
}
catch(Exception e)
{
//MessageBox.Show("SetRegisteredIcon:" + e.Message);
//EventLog.WriteEntry(source, e.Message);
}


}
//Show Finished Notification
void SetFinishedIcon()
{
try
{
CreateNotifyIcon();
trayIcon.Icon = BizBrain_CacheLoader.Properties.Resources.Tally;
trayIcon.Text = "Finished Loading Cache";
trayIcon.BalloonTipTitle = "BizBrain Agent Cache Loader";
trayIcon.BalloonTipText = "Caching Completed";
trayIcon.BalloonTipIcon = ToolTipIcon.Info;
trayIcon.ShowBalloonTip(5000);
}
catch (Exception e)
{
MessageBox.Show("StopProcess:" + e.Message);
//EventLog.WriteEntry(source, e.Message);
}

}

Thanks

Continue reading...
 
Back
Top