'How to export EMF files from eyeshot in the background?

I want to export an emf image file from eyeshot in background, but can not generate it successfully. Here is my code:

using (devDept.Eyeshot.Design VP = new MyDesign())
{
    VP.CreateControl();
    VP.Viewports.Add(new Viewport());
    Line line = new Line(Point3D.Origin, new Point3D(1000,1000,0));
    VP.Entities.Add(line);
    VP.Entities.Regen();
    VP.Invalidate();

    VP.WriteToFileVector(false, "c:/1.emf");
}

Thanks.



Solution 1:[1]

You cannot run asynhcronous workunits inside a using statements because in this way the Design is disposed before the work is completed. So you should avoid the using keyword. If you want to Dispose the the VP after the work is completed you can subscribe to the work completed event handler and dispose the sender. Here is a sample code:

devDept.Eyeshot.Design VP = new Design();

VP.CreateControl();

VP.Viewports.Add(new Viewport());

Line line = new Line(Point3D.Origin, new Point3D(1000, 1000, 0));

VP.Entities.Add(line);

VP.Entities.Regen();

VP.Invalidate();

VP.WriteToFileVector(false, fileName);

VP.WorkCompleted += (s, eventArgs) => ((Design)s).Dispose();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Antonio Spagnuolo