DotNet BackGroundWorker and setclipboardBitmap function

Hi to all.
Thank LoneRobot for his post MultiThreading in 3D Studio Max using the BackgroundWorker class
I'm trying to use DotNet BackGroundWorker to add bitmaps to Imagelist
As is known dotNet supports only for few image formats
But there is a trick: you can open a picture with 3ds Max (openbitmap) and then put it into clipboard (setclipboardBitmap)
Then open it with the command
((DotNetClass "System.Windows.Forms.Clipboard").GetImage())
It works in this example: http://www.scriptspot.com/files/GetClipBoardImage.ms
But when using BackGroundWorker bitmap is not loaded into the clipboard.

Fn WorkThread sender e =
(	
	for i = 1 to fileArray do 
		(
			my_img=openbitmap fileArray[i]
			if my_img != undefined then (
				setclipboardBitmap my_img
				format "ClipBoardImage: %\n"  ((DotNetClass "System.Windows.Forms.Clipboard").ContainsImage())
			)		
		)				
 
)

--------------------------------------
Regards,
Alexander

AttachmentSize
GetClipBoardImage.ms1.02 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kstudio's picture

The solution is found. The

The solution is found.
The most difficult task (opening image), we solve using BackgroundWorker.
After adding all bitmaps in the array we put them into the clipboard.

dotNet.addEventHandler MainThread "RunWorkerCompleted" ShowBitmap

local imgArray = #()
 
Fn ShowBitmap sender e =
(
	for my_img in imgArray do
	(
		(setclipboardBitmap my_img)
		format "ClipBoardImage:% \n"  ((DotNetClass "System.Windows.Forms.Clipboard").ContainsImage())
	)
)
 
Fn WorkThread sender e =
(
for i = 1 to ListArray.count do
		(
		if doesFileExist ListArray[i][6] then
			(
				my_img=openbitmap ListArray[i]
 
			if my_img != undefined then
				(
 				append imgArray my_img
				close my_img
				)
			)
		)
)
 
MainThread = dotnetobject "CSharpUtilities.SynchronizingBackgroundWorker"
 
MainThread.WorkerSupportsCancellation = true
dotNet.addEventHandler MainThread "DoWork" WorkThread
dotNet.addEventHandler MainThread "RunWorkerCompleted" ShowBitmap

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.