Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
.NET
»
Topic:
How to update AutoCAD GUI from other threads?
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: How to update AutoCAD GUI from other threads? (Read 370 times)
0 Members and 1 Guest are viewing this topic.
Andrey Bushman
Swamp Rat
Posts: 864
How to update AutoCAD GUI from other threads?
«
on:
January 21, 2024, 01:22:39 PM »
Windows 10 x64.
AutoCAD 2024.
.Net Framework 4.8.1
Visual Studio 2022
Custom plugin does some long work in the parallel thread. How to initialize updating the StatusBar custom Pane icon when that thread will be finished? In WPF or WinForms I am to update the GUI from other thead via Dispatcher. But how to get something like Dispatcher for AutoCAD?
Code - C#:
[Select]
using
System.Threading.Tasks
;
using
AcWin
=
Autodesk
.
AutoCAD
.
Windows
;
using
acad
=
Autodesk
.
AutoCAD
.
ApplicationServices
.
Application
;
using
System.IO
;
using
System.Drawing
;
using
System.Threading
;
namespace
Bushman
.
AutoCAD
.
Examples
.
Gui
{
public
static
class
StatusBarExamples
{
static
readonly
Icon updateIcon
=
new
Icon
(
Path
.
Combine
(
Path
.
GetDirectoryName
(
typeof
(
StatusBarExamples
)
.
Assembly
.
Location
)
,
@"Icons\update_32.ico"
)
)
;
static
readonly
Icon downloadIcon
=
new
Icon
(
Path
.
Combine
(
Path
.
GetDirectoryName
(
typeof
(
StatusBarExamples
)
.
Assembly
.
Location
)
,
@"Icons\download_32.ico"
)
)
;
static
bool
isUpdateIcon
=
true
;
public
static
void
AddCustomPane
(
)
{
var
statusBar
=
acad
.
StatusBar
;
var
doc
=
acad
.
DocumentManager
.
CurrentDocument
;
if
(
doc
==
null
)
return
;
var
ed
=
doc
.
Editor
;
Icon getIcon
(
)
{
return
isUpdateIcon
?
updateIcon
:
downloadIcon
;
}
;
string
getTooltip
(
)
{
return
isUpdateIcon
?
"Updating is avaliable"
:
"Updating is downloaded"
;
}
;
var
customPane
=
new
AcWin
.
Pane
{
ToolTipText
=
getTooltip
(
)
,
Style
=
AcWin
.
PaneStyles
.
Normal
|
AcWin
.
PaneStyles
.
Command
,
Icon
=
getIcon
(
)
,
}
;
// It works fine
/* customPane.MouseDown += (o, e) => {
var pane = o as AcWin.Pane;
pane.Icon = getIcon();
pane.ToolTipText = getTooltip();
isUpdateIcon = !isUpdateIcon;
statusBar.Update();
}; */
// It doesn't change the icon and tooltip:
customPane
.
MouseDown
+=
(
o, e
)
=>
{
Task
.
Run
(
(
)
=>
{
Thread
.
Sleep
(
3000
)
;
// some long work...
// In WPF or WinForms I am to update GUI from other thead via Dispatcher.
// But how to get something like Dispatcher for AutoCAD?
var
pane
=
o
as
AcWin
.
Pane
;
pane
.
Icon
=
getIcon
(
)
;
pane
.
ToolTipText
=
getTooltip
(
)
;
isUpdateIcon
=
!
isUpdateIcon
;
statusBar
.
Update
(
)
;
}
)
;
}
;
statusBar
.
Panes
.
Add
(
customPane
)
;
}
}
}
Thank you.
Logged
Andrey Bushman
Swamp Rat
Posts: 864
Re: How to update AutoCAD GUI from other threads?
«
Reply #1 on:
January 22, 2024, 12:02:15 PM »
The problem is solved. Sorry, I can't remove this topic.
«
Last Edit: January 22, 2024, 12:12:43 PM by Andrey Bushman
»
Logged
kdub_nz
Mesozoic keyThumper
SuperMod
Water Moccasin
Posts: 2140
class keyThumper<T>:ILazy<T>
Re: How to update AutoCAD GUI from other threads?
«
Reply #2 on:
January 22, 2024, 02:02:04 PM »
What was the solution Andrey ?
Logged
Called Kerry in my other life
Retired; but they dragged me back in !
I live at UTC + 13.00
---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
.NET
»
Topic:
How to update AutoCAD GUI from other threads?