简体   繁体   中英

Paint event of Picture box in windows form application not being called by iis hosted web api

I have created a Asp.Net Windows Form Application. The exe of this application is invoked by another Asp.Net Web API.

Whenever I run the WebApi on local, the exe is invoked and the paint event defined in the exe is executed and saves the result (here an image) at a particular location.

Code of WebApi to invoke the exe:

System.Diagnostics.ProcessStartInfo startInfo;
Process p = new Process();
startInfo = new System.Diagnostics.ProcessStartInfo(@"F:\PolygonsMarking\howto_draw_polygons\bin\Debug\howto_draw_polygons.exe");
startInfo.Arguments = PolygonVertices.ToString() + " " + backgroundImage + " " + tile;//pass arguments to exe
p.StartInfo = startInfo;
p.Start();//execute exe
return Request.CreateResponse(HttpStatusCode.OK);

Code of Exe to accept arguments passed and call the paint event:

public Form1(string[] arguments)
{
    InitializeComponent();

    if (arguments != null)
    {
        BackImagePath = arguments[1];
        TileImagePath = arguments[2];
        string vertices = Convert.ToString(arguments[0]);
        polypoint = vertices.Split(',').ToArray();
        picCanvas.Paint += new PaintEventHandler(picCanvas_Paint);//call paint event                                   
    }                      
}
private void picCanvas_Paint(object sender, PaintEventArgs e)
{
    Image img1 = Image.FromFile(@""+BackImagePath+"");//F:\PolygonsMarking\howto_draw_polygons\image2_1762.png");
    picCanvas.Image = img1;
    Bitmap bmp = new Bitmap(picCanvas.Image);
    LogWriter.LogFileWriter("\nin paint canvas");
    Graphics g = Graphics.FromImage(bmp);
    //some code ahead
}

The code works fine when API is run on local, but when I host the Web API on IIS version 8.0 and run the hosted site the exe is invoked but the paint event code is not executed.

I figured a workaround for making it work as required. Instead of writing my code inside the picCanvas_Paint event I created a simple function with required arguments and called the same in place of calling the paint event.

And now the it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM