The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
How to call ProjectionManager StartProjectingAsync to mirror device desktop from .Net Console app RRS feed

  • Question

  • How can I use the ProjectionManager.StartProjectingAsync to just start mirroring the current desktop.

    The sample in Windows-universal-samples-master.zip
    Doesn't really do what I want. I don't want to create any new windows etc.

    Just project the desktop nothing else.

    I want the projection PC to show exactly what is on main PC.

    This works fine if the projection is started from Windows with:

    start explorer.exe ms-settings-connectabledevices:devicediscovery

    But that means having to show Windows UI and have user select the projector etc.

    I want to do this automatically and show no windows UI and using .Net Framework

    So far I got this C# console app (see below) 

    It works but it means I have to ignore an exception:

    Name Value Type
    ex.Message "Catastrophic failure\r\n\r\nCatastrophic failure\r\n" string

    But the projection is still started and it works even if I pass in 0 and 0

    It is ugly but works.
    Does anyone have a better solution?
    Also it would be nice to be able to disconnect as well.

    /JD

    using System;
    using System.Threading.Tasks;
    using Windows.Devices.Enumeration;
    using Windows.UI.ViewManagement;

    namespace StartProj
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Pass in the name of the PC that we like to project to
                if(args.Length > 0)
                    GetProjector(args[0]).GetAwaiter().GetResult();           
            }
            private static async Task GetProjector(string name)
            {
                try
                {
                    //Get list of available projectors
                    var projectorSelectorQuery = ProjectionManager.GetDeviceSelector();
                    var outputDevices = await DeviceInformation.FindAllAsync(projectorSelectorQuery);
     
                    // Loop through all devices and find match
                    for (int i = 0; i < outputDevices.Count; i++)
                    {
                        var device = outputDevices[i];
                        if(device.Name == name)
                        {
                            try
                            {
                                //Start projector for device
                                await ProjectionManager.StartProjectingAsync(0, 0, device);
                            }
                            catch(Exception ex)
                            {
                                //Ignore this exception
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
    }

     

    Friday, October 18, 2019 4:58 AM

All replies

  • ProjectionManager  method is used to project uwp app views to multiple monitor. For console app, please post this case to related  forum.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 18, 2019 1:55 PM
  • Can you show a similar example with UWP app, without opening new windows?
    As "
    Projection" project  sample in Windows-universal-samples-master.zip

    Basically what I like to find out if how to call ProjectionManager.StartProjectingAsync and only project the current desktop. Just like the  

    start explorer.exe ms-settings-connectabledevices:devicediscovery does.
    I don't want any new windows to pop up etc.
    Just duplicate PC1 screen to PC2 screen
    So it makes no sense to set 
    projectionViewId
    or
    anchorViewId

    Just the 
    displayDeviceInfo

    That is what I an showing in the code above.

    Also what exactly is causing the "Catastrophic failure"

    The screen projection starts fine, what is the problem really? 



    Friday, October 18, 2019 3:08 PM