Hi,guys.I want using mutiple threads to operate CAD. But See code below.
Imports Autodesk.AutoCAD.Runtime Imports qApp = Autodesk.AutoCAD.ApplicationServices 'System ref Imports Autodesk.AutoCAD.Interop Imports System.Windows.Forms Imports System.Windows.Forms.Integration Imports System.Runtime.InteropServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Imports System.Text.RegularExpressions Imports Seg_CADCommon.SegCommon.CAD Imports System.Threading Dim t As Thread Public Sub Gettid() Dim doc As qApp.Document = qApp.Application.DocumentManager.MdiActiveDocument MsgBox(doc Is Nothing) ' operate.Textptid.GetTid(True, doc, Mpttextlist) End Sub <CommandMethod("Ststart", CommandFlags.Session)> _ Public Sub Ststart() Try t = New Thread(AddressOf Gettid) t.Start() Catch End Try End Sub <CommandMethod("Stabort", CommandFlags.Session)> _ Public Sub Stabort() Try t.Abort() Catch End Try End Sub <CommandMethod("Stmessg", CommandFlags.Session)> _ Public Sub Stmessg() Try 'qApp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Mpttextlist.Count) Catch End Try End Sub
But When I Start the thread. It tells me that doc is nothing. You can Test it. I don't understand why doc is nothing. I want use the doc in this thread.
Thank you in advance.
while that's what seems to be the general consensus (no multi-threading in acad plugins) I found that it is possible to have acad objects shared between threads. Check out the following discussion: I posted a solution at end of it. It also has links that might help in your case as well.
What, precisely, do you need multi-threading capability for?