为什么此代码无法在Windows 8.1中运行(通过VS 2010工作)

时间:2014-01-31 22:20:55

标签: c# .net wpf windows-8.1

我有Windows 8.1,我正在尝试在Windows 7和Windows中运行良好的应用程序。 8工作。

我在安装应用程序后出现此错误

A timeout (30000 milliseconds) was reached while waiting for a transaction response from the BrokerInfrastructure service.

我也尝试过可比性模式,但似乎没有任何效果。我只能通过运行它来在VS 2010中使用它。

<Window x:Class="EyeCare.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"   
        WindowState="Minimized"
        Background="Orange" 
        KeyDown="Window_KeyDown"
        >
    <Grid>
    </Grid>
</Window>

 /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            IScheduler sched = schedFact.GetScheduler();

            IDictionary<string, object> map = new Dictionary<string, object>();
            map.Add("window", this);

            IJobDetail job = JobBuilder.Create<ShowJob>()
             .WithIdentity("showJob", "group")
             .UsingJobData(new JobDataMap(map))
             .Build();

            ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("showTrigger", "group")
              .StartNow()
              .WithSimpleSchedule(x => x.WithIntervalInMinutes(20).RepeatForever())
              .Build();

            sched.ScheduleJob(job, trigger);
            sched.Start();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Pause)
            {
                this.Hide();
            }
        }
    }


class ShowJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Window win = context.JobDetail.JobDataMap.Get("window") as Window;
            if (win != null)
            {
                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    win.Width = System.Windows.SystemParameters.FullPrimaryScreenWidth;
                    win.Height = System.Windows.SystemParameters.FullPrimaryScreenHeight;
                    win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    win.WindowStyle = WindowStyle.None;
                    win.Topmost = true;
                    win.WindowState = WindowState.Maximized;
                    win.Show();
                }));

                IDictionary<string, object> map = new Dictionary<string, object>();
                map.Add("window", win);

                IJobDetail job = JobBuilder.Create<HideJob>()
                 .WithIdentity("hideJob", "group")
                 .UsingJobData(new JobDataMap(map))
                 .Build();

                ITrigger trigger = TriggerBuilder.Create()
                  .WithIdentity("hideTrigger", "group")
                  .StartAt(DateBuilder.FutureDate(20, IntervalUnit.Second))
                  .Build();

                context.Scheduler.ScheduleJob(job, trigger);
            }
        }
    }


   class HideJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Window win = context.JobDetail.JobDataMap.Get("window") as Window;
            if (win != null && Application.Current != null)
            {
                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    win.Hide();
                }));
            }
        }
    }

0 个答案:

没有答案