Author Topic: AcCoreConsole causes AutoCAD to flicker  (Read 16785 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6144
AcCoreConsole causes AutoCAD to flicker
« on: June 07, 2012, 07:52:02 PM »
Has anyone had the same the problem with AcCoreConsole causing AutoCAD to flicker.
 
 
It causes AutoCAD to flicker if ran from a AutoCAD command or from a total different .exe(WinForm, WPF, etc...)
 
 
Is it something that can be changed in the creation of the process object?
 
Code - C#: [Select]
  1.  
  2.         static Task<CoreConsoleResult> RunAcCoreConsole(CoreConsoleStartInfo ccsi)
  3.         {
  4.             Task<CoreConsoleResult> task = Task.Factory.StartNew<CoreConsoleResult>(() =>
  5.             {
  6.                 CoreConsoleResult ccr;
  7.                 using (Process process = new Process())
  8.                 {
  9.                     ProcessStartInfo startInfo = new ProcessStartInfo();
  10.                     startInfo.FileName = acCoreConsolePath;
  11.                     string ApplicationArguments = string.Format("/i \"{0}\" /s \"{1}\" /isolate CoreConsole", ccsi.FileName, ccsi.ScriptFilePath);
  12.                     startInfo.Arguments = ApplicationArguments;
  13.                     startInfo.UseShellExecute = false;
  14.                     startInfo.CreateNoWindow = true;
  15.                     startInfo.RedirectStandardOutput = true;
  16.                     process.StartInfo = startInfo;
  17.                     process.Start();
  18.                     process.WaitForExit();
  19.                     ccr = new CoreConsoleResult(ccsi.FileName, process.StandardOutput.ReadToEnd());
  20.        
  21.                 }
  22.                 return ccr;
  23.             });
  24.             return task;
  25.         }
  26.  
  27.  

 

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #1 on: June 08, 2012, 03:27:13 AM »
I think that it is the next bug in AcCoreConsole realization. It is are additional problem to problems which are listed here.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #2 on: June 09, 2012, 05:18:04 PM »
Noticed it causes every window to flicker, Outlook, IE, etc........
 
It is like they are iterating through all the windows.
 
« Last Edit: June 09, 2012, 10:00:06 PM by Jeff H »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #3 on: June 14, 2012, 05:28:39 AM »
ADN reported they could not reproduce the error so threw this together for them to test
Also notice it with ADN example from here
Just pay attention while selecting different drawings in list box or when run a command.

I will be attaching some code that was thrown together quickly and sloppy just for a example to see if you experience the same issue, I am using a total different approach but this still shows the problem. So pay NO attention to efficiency, style or anything alike but is just for producing a issue. Also no error handling

Especially watch the "BIG A" at top left, but still notice it with ADN example but not so noticeable as doing one drawing.

Some notes about code:
The path to accoreconsole.exe is hard-coded to
"C:\Program Files\Autodesk\AutoCAD 2013\accoreconsole.exe" in CoreConsole class. So might need to change it

It will create a script file to your MyDocuments folder but delete it if no errors(could handle that in finally block).
It should create create a process for each core on your machine and when one finishes it will create another until all files have been done.   
So for a quad core machine then no more than 4 accoreconsole.exe processes should run at one time and creating a new one when one of them finishes.
or for a duo core same as above but max of 2 accoreconsole.exe  processes should run at one time.
 
If debug or run .exe in release folder you should click the button on WPF form and it should let you select folder.
Then for every drawing in the folder it will change all entities in ModelSpace to a random different color.

Depending on your machine here are some different size drawings to test with. They all have at least 24 drawings with 500 to 15,000 entities.

Below are some links with dwg's you can test with.
These folders contain drawings with just lines. circles, & arcs.
Contains 24 drawings with 500 entities each.
https://dl.dropbox.com/u/17374049/Test_500_24.zip
Contains 48 drawings with 500 entities each.
https://dl.dropbox.com/u/17374049/Test_500_48.zip
Contains 24 drawings with 5000 entities each.
https://dl.dropbox.com/u/17374049/Test_5000_24.zip
Contains 24 drawings with 15000 entities each.
https://dl.dropbox.com/u/17374049/Test_15000_24.zip


Added a webbrowser that defaults to the TheSwamp for no particular reason.
Should notice accoreconsole' running in taskmanager but all windows flicker when process id changes.
The button opens a FolderBrowserDialog box to select one folders downloaded from above.

 

 
Source code attached at bottom.
 
Again I am using a different approach than this example but this was just thrown together for ADN to see if they expirence the same problem, but basiclly uses the WaitAllOnebyOne appraoch with a limit on total number of processes at one time.
 
Code - C#: [Select]
  1.  
  2.   int cores = 0;
  3.             foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
  4.             {
  5.                 cores += int.Parse(item["NumberOfCores"].ToString());
  6.             }
  7.             int numofFiles = fis.Length;
  8.             int fileIndex = 0;
  9.             List<Task<CoreConsoleResult>> tasks = new List<Task<CoreConsoleResult>>();
  10.             int totalTaskCreated = 0;
  11.             if (numofFiles > cores)
  12.             {
  13.                 for (int i = 0; i < cores; i++)
  14.                 {
  15.                     CoreConsoleStartInfo ccsi = new CoreConsoleStartInfo(fis[fileIndex].FullName, scriptPath);
  16.                     Task<CoreConsoleResult> t = RunAcCoreConsole(ccsi);
  17.                     tasks.Add(t);
  18.                     fileIndex++;
  19.                     totalTaskCreated++;
  20.                 }
  21.             }
  22.             else
  23.             {
  24.                 for (int i = 0; i < numofFiles; i++)
  25.                 {
  26.                     CoreConsoleStartInfo ccsi = new CoreConsoleStartInfo(fis[fileIndex].FullName, scriptPath);
  27.                     Task<CoreConsoleResult> t = RunAcCoreConsole(ccsi);
  28.                     tasks.Add(t);
  29.                     fileIndex++;
  30.                     totalTaskCreated++;
  31.                 }
  32.             }
  33.             int done = 0;
  34.             while (done < numofFiles)
  35.             {
  36.                 int index = Task.WaitAny(tasks.ToArray());
  37.                 done++;
  38.                 tasks.RemoveAt(index);
  39.                 if (totalTaskCreated < numofFiles)
  40.                 {
  41.                     CoreConsoleStartInfo ccsi = new CoreConsoleStartInfo(fis[fileIndex].FullName, scriptPath);
  42.                     Task<CoreConsoleResult> t = RunAcCoreConsole(ccsi);
  43.                     tasks.Add(t);
  44.                     totalTaskCreated++;
  45.                     if (fileIndex < numofFiles - 1)
  46.                         fileIndex++;
  47.                 }
  48.             }
  49.             sb.DeleteScriptFile();
  50.         }
  51.  
  52.         static Task<CoreConsoleResult> RunAcCoreConsole(CoreConsoleStartInfo ccsi)
  53.         {
  54.             Task<CoreConsoleResult> task = Task.Factory.StartNew<CoreConsoleResult>(() =>
  55.             {
  56.                 CoreConsoleResult ccr;
  57.                 using (Process process = new Process())
  58.                 {
  59.                     ProcessStartInfo startInfo = new ProcessStartInfo();
  60.                     startInfo.FileName = acCoreConsolePath;
  61.                     string ApplicationArguments = string.Format("/i \"{0}\" /s \"{1}\" /isolate CoreConsole", ccsi.FileName, ccsi.ScriptFilePath);
  62.                     startInfo.Arguments = ApplicationArguments;
  63.                     startInfo.UseShellExecute = false;
  64.                     startInfo.CreateNoWindow = true;
  65.                     startInfo.RedirectStandardOutput = true;
  66.                     process.StartInfo = startInfo;
  67.                     process.Start();                  
  68.                     ccr = new CoreConsoleResult(ccsi.FileName, process.StandardOutput.ReadToEnd());
  69.                     process.WaitForExit();
  70.                 }
  71.                 return ccr;
  72.             });
  73.             return task;
  74.         }
  75.  

Will post approach I am taking when I get time to do more testing and refactor.
 
 
 
Windows 7 64 bit.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #4 on: June 15, 2012, 11:15:17 AM »
I do not know ADN says they cannot reproduce it.
 
Here is a screencast of ADN running it but they changed to show the window and not redirect output.
ADN ScreenCast
 
I tried those same settings but here is how it works on 2 machines I tested.
Notice how it flickers and the mous disappears the Big A up top disappears.
My ScreenCast
 
Any idea what would cause this?

vegbruiser

  • Guest
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #5 on: June 18, 2012, 05:44:15 AM »
I've just downloaded, compiled and run the console app you wrote.

I noticed a little bit of flickering in the app itself, which I assume is down to it attempting to maintain focus? But none of my other programs had any problems. (I have Outlook and Google Chrome open in perpetuity.)

Sorry I can't be of any further help.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #6 on: June 18, 2012, 10:26:41 AM »
Thanks.
 
It might have something to do with dual moniters??

vegbruiser

  • Guest
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #7 on: June 18, 2012, 10:31:42 AM »
I do have a dual monitor set-up if that's any consolation.?

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #8 on: June 18, 2012, 10:33:14 AM »
I have no idea what it is but mine flickers like crazy,
 
 
thanks again

TheMaster

  • Guest
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #9 on: June 18, 2012, 12:31:57 PM »
I have no idea what it is but mine flickers like crazy,
 
 
thanks again

Just a note on your approach to asynchronous processing with Core Console.
It doesn't need to be that complicated.

I would just get a list of all files to process, and run it through Parallel.ForEach or
call AsParallel().Select(...) on the list, if there is a result for each file.

Asynchronous programming shouldn't require the programmer to be concerned
with how many CPU cores are available, and Parallel LINQ takes care of all of
that for us.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #10 on: June 18, 2012, 12:42:18 PM »
I tried Parallel.ForEach() but it would launch 2-100+ accoreconsole processes(depending on number of drawings) and that was the only way I knew to keep it down to a certain number.
 
Did not try PLINQ approach.
 
 
 
 
 

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #11 on: June 20, 2012, 11:38:03 AM »
ADN did not notice the flicker but confirmed the cursor disappearing while continuing to work and has reported it, so hopefully it gets fixed, because might as well freeze up the UI instead cursor dissappearing every second or two, which  deafeats he main reason for using it for this context.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #12 on: September 11, 2014, 05:53:43 AM »
Sweet looks like they fixed it in 2015.
Downloaded project and upgraded to .NET 4.5 and change path to 2015 accoreconsole.exe and updated references to point to 2015 dll's.
 
I created a folder with a drawing containing 30,000 circles and copied file in folder then pasted it, copied all files in folder, pasted them, repeat etc.....
Anyways changed the color of 30,000 circles in 768 drawings in couple of minutes.
Time to refactor and fix it up.
 
I got 2 errors out of 768 files looks like the license engine can not keep up.
 

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #13 on: September 16, 2014, 01:06:24 PM »
Starting to refactor, and need to finish cancelation and progress, .......
Code - C#: [Select]
  1.         private ConcurrentQueue<FileInfo> fileQueue;
  2.         public async void ProcessFiles(ICollection<FileInfo> fileInfos, Action<ProgressInfo> pinfo)
  3.         {
  4.             fileQueue = new ConcurrentQueue<FileInfo>(fileInfos);
  5.             int cores = Interop.User32.NumberOfCores();
  6.             Task[] tasks = new Task[cores];
  7.             for (int i = 0; i < cores; i++)
  8.             {
  9.                 tasks[i] = Task.Run(() => RunAcCoreConsole(fileQueue, CTokenSource.Token));
  10.             }
  11.           await Task.WhenAll(tasks);
  12.         }
  13.         private  Task RunAcCoreConsole(ConcurrentQueue<FileInfo> que, CancellationToken ct)
  14.         {
  15.          return  Task.Run(() =>
  16.             {
  17.                 FileInfo file;
  18.                 while (que.TryDequeue(out file))
  19.                 {
  20.                     if(ct.IsCancellationRequested) return;
  21.                     using (Process process = new Process())
  22.                     {
  23.                         process.StartInfo = CreateProcessStartInfo(file);
  24.                         process.Start();
  25.                         process.WaitForExit();
  26.                     }
  27.                 }
  28.             }, ct);
  29.         }
  30.  
  31.  

weslleywang

  • Mosquito
  • Posts: 3
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #14 on: January 30, 2015, 01:31:34 PM »
Hi Jeff:

  I just tried to migration some of my code to use your code here and AU2012, CP3338 Using .NET Programming to Create New Possibilities with the AutoCADŽ Core Consolehttp://au.autodesk.com/au-online/classes-on-demand/class-catalog/2012/autocad/using-net-programming-to-create-new-possibilities-with-the-autocad-core-console by Augusto Goncalves. It really help me start and works really well.
  Now I have this issue, it take a long time for some task (e.g. print to PDF) for some drawings, some other drawing it just hang. How you handle this situation? Does timeout solve this problem? for timeout, I mean, if a Task (process of AcCoreConsole) take longer than a certain time, I will kill it and move to next drawing.


Thank you so much
Wes
AutoCAD (ACA, Map) 2014, Vault 2014, VS 2012 and Windows 7 64