<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic wpf window and autocad not working synchronously in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10128980#M17318</link>
    <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;the plugin functionalities are all ok but the problem is when we do something like.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;AddAcadLine()&lt;/EM&gt; then &lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; then&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt;&amp;nbsp;&lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; ,&lt;/P&gt;&lt;P&gt;what we see is:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; &amp;nbsp;then &lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; then&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt;&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the scenario is we try to add/delete ACAD Objects and we want to see the notifications in the wpfWindow after each&amp;nbsp;add/delete process.&lt;/P&gt;&lt;P&gt;we use&amp;nbsp;&lt;EM&gt;aApp.Application.ShowModelessWindow(wpfWindow);&lt;/EM&gt; for this example.&lt;/P&gt;&lt;P&gt;and C#/VS2019 and Autocad/Civil3d 2018.&lt;/P&gt;&lt;P&gt;thanks in advance, any help will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 07:55:23 GMT</pubDate>
    <dc:creator>essam-salah</dc:creator>
    <dc:date>2021-03-04T07:55:23Z</dc:date>
    <item>
      <title>wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10128980#M17318</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;the plugin functionalities are all ok but the problem is when we do something like.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;AddAcadLine()&lt;/EM&gt; then &lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; then&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt;&amp;nbsp;&lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; ,&lt;/P&gt;&lt;P&gt;what we see is:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; &amp;nbsp;then &lt;EM&gt;UpdateWpfWindow()&lt;/EM&gt; then&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt;&amp;nbsp;&lt;EM&gt;AddAcadLine()&lt;/EM&gt; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the scenario is we try to add/delete ACAD Objects and we want to see the notifications in the wpfWindow after each&amp;nbsp;add/delete process.&lt;/P&gt;&lt;P&gt;we use&amp;nbsp;&lt;EM&gt;aApp.Application.ShowModelessWindow(wpfWindow);&lt;/EM&gt; for this example.&lt;/P&gt;&lt;P&gt;and C#/VS2019 and Autocad/Civil3d 2018.&lt;/P&gt;&lt;P&gt;thanks in advance, any help will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 07:55:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10128980#M17318</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-03-04T07:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10130058#M17319</link>
      <description>&lt;P&gt;You did not say how the methods AddCadxxx() and UpddateWpfWinodw() is called, but yes, using modeless window is the cause of the issue. When making changes to the drawing from a modeless window, it is strongly recommended that you call SendStringToExecute() from the modeless window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you should wrap you drawing change/update code in custom command method or methods, and use SendStringToExecute() in the modeless window user interaction event handler, where you could also add CommandEnded event handler to MdiActiveDocument, so that when the custom command method is done, you can update the modeless window view (as you can see, in this way, you only update your window when the command action is completed), then remove the CommandEnded handler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 14:17:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10130058#M17319</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-03-04T14:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10136891#M17320</link>
      <description>&lt;P&gt;It's because when the focus is on your modeless window, AutoCAD is running in the application context. In this mode, the drawing window is not refreshed until it's got focus. You can use SendStringToExecute() like advised by Norman, or you can use&amp;nbsp;ExecuteInCommandContextAsync() like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;void DrawLineButtonOnClick(object sender, RoutedEventArgs e)
{
    if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.IsApplicationContext)
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.ExecuteInCommandContextAsync(AddLineCallback, null);
    else
        AddLineCallback();
}

static Task AddLineCallback(object o = null)
{
    // Add your line

    return Task.CompletedTask;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Always test if you are in application context because in this case, the callback is not executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&amp;nbsp;ExecuteInCommandContextAsync() is async, so if you want to run code after the call, you need to await the method.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 15:48:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10136891#M17320</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2021-03-07T15:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10137994#M17321</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for reply, about calling&amp;nbsp;&lt;SPAN&gt;SendStringToExecute(), where we can open Transaction and DocumentLock ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i mean should we call&amp;nbsp;SendStringToExecute() from Trans/DocLock or we do it in the other place the custom acad Cmd?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 07:02:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10137994#M17321</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-03-08T07:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10143136#M17322</link>
      <description>&lt;P&gt;Sorry for the late reply. I was thinking to put together some code to demonstrate my suggest would be much better for anyone who is interested in this topic. I decided to publish a working project in my blog here so that with all code for a better readability:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://drive-cad-with-code.blogspot.com/2021/03/modeless-formwindow-do-something-and.html" target="_blank" rel="noopener"&gt;https://drive-cad-with-code.blogspot.com/2021/03/modeless-formwindow-do-something-and.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 19:51:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10143136#M17322</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-03-09T19:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: wpf window and autocad not working synchronously</title>
      <link>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10145144#M17323</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp; many thanks for your effort sir,&lt;/P&gt;&lt;P&gt;i just made the same project you &lt;SPAN&gt;published but in wpf, here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/essamce/AcadWpfModelessDialog" target="_blank"&gt;essamce/AcadWpfModelessDialog (github.com)&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 13:16:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/wpf-window-and-autocad-not-working-synchronously/m-p/10145144#M17323</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-03-10T13:16:46Z</dc:date>
    </item>
  </channel>
</rss>

