Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Remove tray icon in LinqPad
#3
Code:
Copy      Help
// script "Tray icon region.cs"
using (var tir_ = new trayIconRegion()) {
    dialog.show("test", "with tray icon");
}

dialog.show("test", "without tray icon");


/// <summary>
///
Adds tray icon like <see cref="script.trayIcon"/>.
/// Removes it when disposing the variable.
/// </summary>
///
<remarks>
///
Use this in a script instead of <see cref="script.setup"/> if you want to remove the icon earlier than when the script process ends. If you need <c>script.setup</c> for other purposes, make sure its first argument is omitted or <c>false</c>.
/// </remarks>
///
<example>
///
<code><![CDATA[
/// using (var tir_ = new trayIconRegion()) {
///     dialog.show("test", "with tray icon");
/// }
/// dialog.show("test", "without tray icon");
/// ]]></code>
///
</example>
class trayIconRegion : IDisposable {
    trayIcon _ti;
    bool _disposed;
    
    /// <inheritdoc cref="script.trayIcon"/>
    public trayIconRegion(int delay = 500, Action<trayIcon> init = null, Action<trayIcon, popupMenu> menu = null, string f_ = null) {
        script.trayIcon(delay, t => {
            if (!_disposed) {
                _ti = t;
                init?.Invoke(t);
            }
else {
                timer.after(1, _ => { t.Dispose(); });
            }
        },
menu, f_);
    }

    
    /// <summary>
    ///
Removes the tray icon.
    /// </summary>
    public void Dispose() {
        if (!_disposed) {
            _disposed = true;
            if (_ti is { } ti) {
                ti.Dispose();
                _ti = null;
            }
        }
    }
}

In next LA will not need this class. Instead:
Code:
Copy      Help
using (script.trayIcon()) {
    dialog.show("test", "with tray icon");
}

dialog.show("test", "without tray icon");


Messages In This Thread
[split] Remove tray icon in LinqPad - by Davider - 01-26-2026, 07:26 AM
RE: [split] Remove tray icon in LinqPad - by Gintaras - Yesterday, 07:06 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)