Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Remove tray icon in LinqPad
#1
The following code can run successfully in LINQPad 8, but after it finishes executing, the icon still remains in the system tray (bottom-right of the taskbar). I have to manually exit/close the icon before I can run it again.
 
Is this normal behavior?
 
I need the icon to no longer be displayed after the script finishes executing.

 
Code:
Copy      Help
//.
script.setup(trayIcon: true, sleepExit: true);
//..

keys.send("Win+M");

for (int i = 0; i < 3; i++)
{
    using (opt.scope.all())
    { //recorded
        opt.mouse.MoveSpeed = opt.key.KeySpeed = opt.key.TextSpeed = 20;
        var w1 = wnd.find(0, "Program Manager", "Progman");
        mouse.doubleClick(w1, 50, 20);
        mouse.click(w1, 50, 20);
        var w2 = wnd.find(10, "此电脑", "CabinetWClass");
        mouse.click(w2, 68, 164);
        w2.WaitForName(30, "文档");
        mouse.doubleClick(w2, 235, 225);
        w2.WaitForName(30, "leidian9");
        mouse.click(w2, 1088, 19);
    }
}

keys.send("Win+Shift+M");
#2
Probably LP does not end the script process when the code ends executing. But it should have a setting or function to change this (I guess).
#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");
#4
thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)