方法适用于模拟器但Microsoft Surface单元上没有?

时间:2011-02-14 22:28:24

标签: c# .net wpf pixelsense

我有以下代码。 StartRecord方法在Microsoft Surface Unit上出现错误。但是当我在模拟器上测试它时,一切都很好。任何提示如何

1)找到Microsoft Surface Unit上抛出的异常?

2)在代码中找到错误?任何假设?

        private void StartRecord(object sender, ContactEventArgs e)
        {
            isRecording = true;
            StartButton.IsEnabled = false;
            recordTimer = new Timer(10);
            recordTimer.Elapsed += new ElapsedEventHandler(recordTimer_Elapsed);
            PlaybackRoot.Visibility = System.Windows.Visibility.Collapsed;
            EllapsedRecord.Visibility = System.Windows.Visibility.Visible;
            InputLevel.Visibility = System.Windows.Visibility.Visible;
            long time = DateTime.Now.Ticks;
            String fileName = Convert.ToString(time) + ".wav";
            Console.WriteLine(fileName);
            startTime = DateTime.UtcNow;
            recordTimer.Start();
            record = new AudioRecording(fileName);
            record.getSampleAggregator().MaximumCalculated += new EventHandler<MaxSampleEventArgs>(AudioControl_MaximumCalculated);
            record.start();
        }

2 个答案:

答案 0 :(得分:4)

我不熟悉Surface,但是如果你没有任何调试工具,我会先将所有内容包装在try块中,这样就可以检索异常消息和callstack:

try
{
    //Method code here
}
catch (Exception ex)
{
    //Output the exeption messages here, use a recursive method to get those of inner exceptions as well.
    //Example method to get the messages as string:
    //
    //public static string ExceptionToString(Exception ex)
    //{
    //  if (ex == null) return "";
    //  else return " [" + ex.Message + ExceptionToString(ex.InnerException) + "]";
    //}
    //
    //Also get the StackTrace (ex.StackTrace) and print it using whatever means available.
}

这应该允许您将问题进一步缩小到特定操作。

答案 1 :(得分:1)

将Surface置于“管理模式”并从那里运行您的应用程序。此外,请确保您使用的是应用程序的调试版本,而不是发布。