1

I am creating a uwp app with some media and video features, I have tested the app repeatedly on debug mode and it works just perfect as desired, after commenting and uncommenting of some code I was able to figure out that recursion of a specific method is causing the app to crash.

I also tried to display the exception with message dialog ( for release mode ). But no exception caught and app just freezes and crashed.

I run the app once on debug mode and then stop visual studio and then just directly open the app from my PC to test it on release mode.

MyScenario:

I am using OnFileActivated event to open video files directly on double click in my PC with my app. That works just fine. Below I will show you the code and reason for crashing. Please let me know how to solve this. Thanks in advance.

Code

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {

        //Some Media Stuff which works fine everytime even in release mode.
        await speechRecognizer.CompileConstraintsAsync();// I am using speech input to play pause my media player.
        ListenandAct();


    }

 private async void ListenandAct()
    {
        var result = await speechRecognizer.RecognizeAsync();
        if (result.Text == "Pause" || result.Text == "pause")
        {
            Media.Pause();
        }
        else if (result.Text == "Play" || result.Text == "play")
        {
            Media.Play();
        }
        //ListenandAct(); //if I comment this line for recursion the app doesnt crash even in release mode, but If I uncomment it than app works perfect in debug mode but crashes in release mode.
    }

OnFileActivated method in app.xaml.cs

protected async override void OnFileActivated(FileActivatedEventArgs args)
    {
        string ParentName = "";
        if (args.Files.Count > 0)
        {
            Type TargetType = typeof(MainPage);
            if (args.Files.Count == 1)
            {
                SingleFileToPlay = args.Files[0] as StorageFile;
                TargetType = typeof(SingleFilePlay);
            }
            else if (args.Files.Count > 1)
            {
                ParentName = (await (args.Files[0] as StorageFile).GetParentAsync()).DisplayName;
                MultiFilesToPlay = new List<StorageFile>(); 
                TargetType = typeof(MultiFilePlay);
                foreach (var file in args.Files)
                {
                    MultiFilesToPlay.Add(file as StorageFile);
                }
            }
            Frame rootFrame = Window.Current.Content as Frame;
            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            //if (rootFrame.Content == null)
            //{
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            rootFrame.Navigate(TargetType, ParentName);
            //}
            // Ensure the current window is active
            Window.Current.Activate();
        }


    }

NOTE

When I run a video file by double clicking it , it works perfect without crashing, but when my app is already running a video file and I double click another video file again then my app tries to run the second video file, the second video file is shown on the app as it is suposed to and then app freezes and crashes after a couple of seconds.

Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75
  • Sorry, not linked to your error, but any reason you are not doing `result.Text.ToLower()` and check against "pause" only. – Ecnerwal Apr 25 '17 at 20:19
  • no, I dont have any reason for that I was just in development mode for now so I was just testing voice commands for now, but yeah good tip about ToLower method, I will use that thanks :) – Muhammad Touseef Apr 25 '17 at 20:32
  • Have your tried using a while loop instead of recursion? Also could you share a [mcve] that can reproduce your issue? With current code, it's hard to say where the problem is. – Scavenger Apr 27 '17 at 01:59
  • @Scavenger Yes I have tried while loop as well and it gives same problem – Muhammad Touseef Apr 29 '17 at 16:36
  • @Scavenger I have edited the question and added code from method "onfiveactivated" maybe that can help u to undesrstand the problem thnks – Muhammad Touseef Apr 29 '17 at 16:37
  • How did you try to display the exception? `catch` block doesn't catch `StackOverflow` exception. – ravi kumar Jul 03 '17 at 11:03

0 Answers0