Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. namespace Xilium.CefGlue.Samples.WpfOsr
  2. {
  3. using System;
  4. using System.Windows;
  5. internal static class Program
  6. {
  7. [STAThread]
  8. private static int Main(string[] args)
  9. {
  10. try
  11. {
  12. var path = System.IO.Path.Combine(Environment.CurrentDirectory, "cef");
  13. CefRuntime.Load(path);
  14. }
  15. catch (DllNotFoundException ex)
  16. {
  17. MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
  18. return 1;
  19. }
  20. catch (CefRuntimeException ex)
  21. {
  22. MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
  23. return 2;
  24. }
  25. catch (Exception ex)
  26. {
  27. MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
  28. return 3;
  29. }
  30. var mainArgs = new CefMainArgs(args);
  31. var cefApp = new SampleCefApp();
  32. var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp);
  33. if (exitCode != -1) { return exitCode; }
  34. var cefSettings = new CefSettings
  35. {
  36. // BrowserSubprocessPath = browserSubprocessPath,
  37. SingleProcess = false,
  38. WindowlessRenderingEnabled = true,
  39. MultiThreadedMessageLoop = true,
  40. LogSeverity = CefLogSeverity.Error, //CefLogSeverity.Verbose,
  41. LogFile = "cef.log",
  42. };
  43. try
  44. {
  45. CefRuntime.Initialize(mainArgs, cefSettings, cefApp);
  46. }
  47. catch (CefRuntimeException ex)
  48. {
  49. MessageBox.Show(ex.ToString(), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
  50. return 4;
  51. }
  52. var app = new Xilium.CefGlue.Samples.WpfOsr.App();
  53. app.InitializeComponent();
  54. app.Run();
  55. // shutdown CEF
  56. CefRuntime.Shutdown();
  57. return 0;
  58. }
  59. }
  60. }