r1pper / GoPro.Hero

a lightweight c# library to access and control GoPro HERO Action cameras
MIT License
59 stars 21 forks source link

Program stalls #9

Closed jfamvg closed 10 years ago

jfamvg commented 10 years ago

Hello r1pper,

I used you library to connect to my gopro hero3 white edition with a winform application, but when i try to connect: _camera = Camera.Create("10.5.5.9"); my complete program stalls at: SendRequestAsync() -> using (var response = await request.GetResponseAsync() as HttpWebResponse).

When i run the command (http://10.5.5.9/bacpac/sd) with my browser and a console application i get a result.

I hope you have a quick fix.

Greetings, Jens

r1pper commented 10 years ago

@jfamvg Sorry for the late answer

you can't call it directly from UI thread call Camera.Create from another thread or use Camera.CreateAsync to spawn a task for it.

here is an example to retrieve camera name using tasks:

  var task = Task.Run<Camera>(() => Camera.Create<Hero3.Hero3Camera>("10.5.5.9"));
  var cam=task.Result;
  MessageBox.Show(cam.InformationCache().Name);

or in traditional manner in another thread

        var thread = new Thread(CreateCamera);
        thread.Start();

        private void CreateCamera()
        {
            var camera = Camera.Create<Hero3.Hero3Camera>("10.5.5.9");
            //other camera stuff here
        }

in windows forms I think you're better off to call all camera methods from another thread and update UI based on the results.

sorry for the inconvenience, I wrote the library with WinRT and WP in mind and those platforms only support Async model.

Best regards Hessam

r1pper commented 10 years ago

@jfamvg OK, I added a Configuration to switch Http Request mode,

write this line before using the library

 Configuration.CommandRequestMode = Configuration.HttpRequestMode.Sync;

after the change you can call the methods from UI thread

hope this help

Best regards Hessam