1 year ago

#368342

test-img

Yotic

VSIX, Events are deleted after a while

As stated in Events in the vsix experimental instance working only once, I feel that my events are being eaten by the garbage collector, because after a while (about 1 ) events stop working, I put try catch - nothing

await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Wrapper.dte = (DTE)GetGlobalService(typeof(DTE));
/*Wrapper.rdt = GetGlobalService(
typeof(SVsRunningDocumentTable)) as
IVsRunningDocumentTable; */
await HistoryCodingCommand.InitializeAsync(this);
Statistic.Load();
Wrapper.Load();
public static void Load()
{
    try
    {
        doc = dte.ActiveDocument;
        docE = dte.Events.DocumentEvents;
        dte.Events.TextEditorEvents.LineChanged += Handles.LineChanged;
        dte.Events.MiscFilesEvents.ItemAdded += Handles.ItemAdded;
        dte.Events.DocumentEvents.DocumentOpened += Handles.DocumentOpened;
        client.Initialize();
        Updater = new Thread(() =>
        {
            while (true)
            {
                Update();
                Thread.Sleep(1000);                        
            }
        });
        Updater.Start();
    }
    catch (Exception ex) { Log("error:" + ex.Message); }            
}
public void DocumentOpened(Document Document)
{
    try
    {
        Log($"doc_open:{Document.FullName}");
    }
    catch (Exception ex) { Log($"error:{ex.Message}"); }
}
public void ItemAdded(ProjectItem ProjectItem)
{
    try
    {
        Log($"item_add:{ProjectItem.Document.FullName}");
    }
    catch (Exception ex) { Log($"error:{ex.Message}"); }
}
public void LineChanged(TextPoint StartPoint, TextPoint EndPoint, int Hint)
{
    try
    {
        TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;
        var text = activeDoc.CreateEditPoint(StartPoint).GetText(EndPoint);
        Log($"input:{dte.ActiveDocument.FullName};{StartPoint.Line},{StartPoint.LineCharOffset}:{EndPoint.Line},{EndPoint.LineCharOffset};{text}");
        Wrapper.Statistic.WritedCodeChars += text.Length;
        Wrapper.Statistic.WritedCodeLines += text.Where(z => z == '\n').Count();
        Wrapper.Statistic.AddChars(text);
    }
    catch (Exception ex) { Log($"error:{ex.Message + ", " + ex.StackTrace}"); }
}

c#

vsix

0 Answers

Your Answer

Accepted video resources