public Window(Rectangle bounds, int xSize, Config config, IImageSource imageSource)
 {
     Log.Instance.Write("Creating screen saver window at bounds " + bounds);
     this.bounds = bounds;
     this.xSize = xSize;
     this.config = config;
     this.backgroundstyle = config.BackGroundStyle;
     this.imagestyle = config.ImageStyle;
     //this.theme = theme;
     this.imageSource = imageSource;
     this.SetStyle(
         ControlStyles.AllPaintingInWmPaint |
         ControlStyles.UserPaint |
         ControlStyles.OptimizedDoubleBuffer, true);
 }
 public Program(Config config)
 {
     this.config = config;
 }
        static void Main(string[] args)
        {
            try {

                foreach (Process process in Process.GetProcesses())
                    if (process.Id != Process.GetCurrentProcess().Id && process.ProcessName.Equals("YetAnotherPhotoScreenSaverCE"))
                        return;
                if (args.Length > 0)
                    if (args[0].ToLower().Contains("/p"))
                        return;
                    else if (args[0].ToLower().Contains("/c")) {
                        Application.Run(new ConfigWindow());
                        return;
                    }

                Config config = new Config();
                Program program = new Program(config);
                program.End += (obj, e) => {
                    Log.Instance.Write("Stopping screen saver");
                    program.Stop();
                    Application.Exit();
                };
                program.Run();
                Application.Run();
            }
            catch (Exception ex) {
                Log.Instance.Write("Unhandled exception on main thread", ex);
            }
            finally {
                // just in case of abnormal termination
            }
        }