Connect with us

Microsoft

Making the app single-instanced (Part 3)

Single-instanced apps only allow one instance of the app running at a time. WinUI apps are multi-instanced by default. They allow you to launch multiple instances of the same app at one time, which we call multiple instances. However, you may implement single-instancing based on the use case of your app. Attempting to launch a…

Published

on

[]Single-instanced apps only allow one instance of the app running at a time. WinUI apps are multi-instanced by default. They allow you to launch multiple instances of the same app at one time, which we call multiple instances. However, you may implement single-instancing based on the use case of your app. Attempting to launch a second instance of a single-instanced app will only result in the first instance’s main window being activated instead. This tutorial demonstrates how to implement single-instancing.

[]By the end of this section, you will be able to: 1. Turn off XAML’s generated Program code 2. Define customized MAIN method for redirection 3. Test single-instancing via app deployment

Turn off XAML’s generated Program code

[]We need to check for redirection as early as possible, and before creating any windows. To do this, we must define the symbol “DISABLE_XAML_GENERATED_MAIN” in the project build properties.

  1. Double-click on the project name in Solution Explorer:
  2. Define the DISABLE_XAML_GENERATED_MAIN symbol below

[]DrumPad:

DISABLE_XAML_GENERATED_MAIN DISABLE_XAML_GENERATED_MAIN DISABLE_XAML_GENERATED_MAIN DISABLE_XAML_GENERATED_MAIN DISABLE_XAML_GENERATED_MAIN DISABLE_XAML_GENERATED_MAIN

Define a customized Program class with a Main method

[]A customized Program.cs file is created instead of running the default Main method because it enables the app to check for redirection, which is not what WinUI apps default to doing.

  1. Navigate to Solution Explorer -> Right-click on the project name -> Add -> New Item
  2. Under Visual C# Items -> Code -> Class -> Name it Program.cs -> Add

[]NOTE: Your project should look like this:

[]    3. Add the following namespaces:

[]Program.cs:

using System.Threading; using Microsoft.UI.Dispatching; using Microsoft.Windows.AppLifecycle; using Windows.ApplicationModel.Activation; using Windows.Storage; []4. Replace the empty class Program with following:

[]Program.cs:

{ [STAThread] static async Task Main(string[] args) { WinRT.ComWrappersSupport.InitializeComWrappers(); bool isRedirect = await DecideRedirection(); if (!isRedirect) { Microsoft.UI.Xaml.Application.Start((p) => { var context = new DispatcherQueueSynchronizationContext( DispatcherQueue.GetForCurrentThread()); SynchronizationContext.SetSynchronizationContext(context); new App(); }); } return 0; } } []NOTE: Main determines if it should redirect or launch a new app instance via DecideRedirection();

[]5. Define DecideRedirection() below the Main method:

[]Program.cs:

private static async Task DecideRedirection() { bool isRedirect = false; AppActivationArguments args = AppInstance.GetCurrent().GetActivatedEventArgs(); ExtendedActivationKind kind = args.Kind; AppInstance keyInstance = AppInstance.FindOrRegisterForKey(“randomKey”); if (keyInstance.IsCurrent) { keyInstance.Activated += OnActivated; } else { isRedirect = true; await keyInstance.RedirectActivationToAsync(args); } return isRedirect; } []NOTE: DecideRedirection determines if the app has been registered by registering a key that represents your app instance. Based on the result of key registration, it infers if there is a current app instancing running; therefore, whether or not to redirect or allow the app to launch for the first time

[]6. Define the helper method OnActivated(), below the DecideRedirection method:

[]Program.cs:

private static void OnActivated(object sender, AppActivationArguments args) { ExtendedActivationKind kind = args.Kind; }

Testing single-instancing via app deployment

[]Up until now, we have been testing our app by running the solution debugger. We can only have one debugger running at once. Therefore, it prevents us from knowing whether the app is single-instanced because we can’t debug the same project solution twice at the same time. To test, we will deploy the application. After deploying, we can launch the app from the desktop like how you would with Microsoft Word.

  1. Navigate to Solution Explorer -> Right-click on the project name -> Deploy
  2. Open the start menu and click on the search field
  3. Type “DrumPad” (or your app’s name) in the search field
  4. Click on the app icon from the search result to launch the app
  5. Repeat steps 2 to 4 to launch the same app again and see if another instance pops up

Result

Wrapping up

  • In part 1, we learned how to use WinUI 3 controls to create the app’s visual layer.
  • In part 2, we introduced the concepts of dark mode and windowing.
  • In part 3, we enforced single-instancing for our app.

[]All the code we have covered from the blog series is on GitHub, with branches for the different steps. The main branch is the most comprehensive. The other branches are intended to show you how the app architecture evolved.

Further learning

[]Here are some links to check out with resources on building for WinUI 3 apps with WinAppSDK. Don’t stop learning!

[]More examples:

[]Official documentation:

[]Now that you have the basic app built, you can easily add other controls from the WinUI 3 Controls Gallery and experiment other cool WinAppSDK features to enhance your Windows apps!

Source

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published.

Business

Accelerate sustainability progress and business growth with Microsoft Cloud for Sustainability — starting June 1

It’s a moment we’ve been building toward — new capabilities from Microsoft Cloud for Sustainability that will enable faster, broader transformation for organizations at varying stages of their sustainability journey. We are pleased to announce the general availability of Cloud for Sustainability on June 1. Now, a growing set of ESG (environmental, social and governance)…

Published

on

By

It’s a moment we’ve been building toward — new capabilities from Microsoft Cloud for Sustainability that will enable faster, broader transformation for organizations at varying stages of their sustainability journey. We are pleased to announce the general availability of Cloud for Sustainability on June 1.

Now, a growing set of ESG (environmental, social and governance) capabilities from Microsoft and our global ecosystem of partners will give organizations the opportunity to accelerate their progress and business growth.

Watch the video.

Turning sustainability commitments into action with better data intelligence

To stabilize our future and build more quickly toward a global net-zero carbon economy, organizations of all types, sizes and sectors are facing the need to transform common practices. This includes more effectively managing their environmental footprint, embedding sustainability through their organizations and value chains, and making strategic business investments that drive value. And this starts with solving a data problem.

Organizations need more accessible, centralized data intelligence to make the high-stakes decisions that are required right now to address complex issues, weighing both business and ESG criteria to direct capital toward investment opportunities that balance growth and impact.

Wherever organizations are in their sustainability journey, together, we can accelerate progress to reach our collective goals.

Microsoft is energized about helping our customers accelerate their progress. Microsoft Cloud for Sustainability solutions will provide the intelligence and data management capabilities organizations need to respond to changes with agility and confidence.

Building on more than a decade of work on sustainability

Our own sustainability journey began when we set our first carbon goal more than a decade ago. This led us to better organize our data and realign our company’s vision and strategy with our sustainability goals. We continue to build on our commitments to innovate and invest in technologies that address environmental sustainability and to transparently share our achievements and setbacks so that we can all learn together. We’re also considering how to deliver on our ESG commitments while continuing to grow our business and drive shareholder value — not an easy challenge!

Now, with the release of Microsoft Cloud for Sustainability, we’re bringing together powerful capabilities delivered by Microsoft and our partners to help organizations:

Unify data intelligence. To effectively drive sustainability reporting, sustainability efforts, and business transformation, organizations need better visibility into activities across their enterprise and value chain. Collecting and connecting IoT data from devices using sensors — combined with rich services at the edge or in the cloud — provides the basis to monitor and measure activities at scale. And now, Microsoft Sustainability Manager will empower organizations to more easily record, report and reduce their environmental impact through increasingly automated data connections that deliver actionable insights.

This extensible Microsoft Cloud for Sustainability solution centralizes previously disparate data in a common data format and offers organizations an increasingly comprehensive view into the emissions impact of their entire operations and value chain.

Sustainability Manager is available for a free test drive or to purchase June 1.

Build more enduring IT infrastructures. Organizations can reduce their environmental impact and increase business value when they replace tools, systems, or activities with more efficient options. Moving workloads to the cloud, for example, can increase both carbon and energy efficiencies. Emissions Impact Dashboard applications provide Microsoft customers with transparency into emissions produced from their use of Microsoft cloud services. Devices also contribute to an organization’s environmental footprint. Surface devices maximize sustainability of materials and extend product life while minimizing product carbon footprint and energy consumption.

Reduce the environmental impact of operations. With digital solutions delivered through Microsoft and our growing partner ecosystem, we’re already helping organizations maximize asset and production efficiencies, reduce the environmental impact of their buildings and spaces, and advance their transition to clean energy.

Create more sustainable value chains. Digital technologies are also helping organizations facilitate greater transparency and accountability through their value chain, from raw materials to product creation to distribution. A data-first approach can help organizations achieve data integrity and gain the visibility they need to drive efficiencies, reduce emissions and design out waste.

Learn more about how we’re helping organizations achieve positive impact on Microsoft.com/sustainability.

Global partners, a critical piece to extending impact

Much of this important work is being achieved through collaboration with our global ecosystem of partners who have helped us land our ambitions and transform our business. Today, they’re also pivotal to helping customers advance sustainability through robust, innovative solutions powered by the Microsoft Cloud.

Microsoft Cloud for Sustainability partner solutions span industries, from transportation to real estate to manufacturing, such as these early solutions that are already in market:

There are many more solutions coming. Our sustainability partner ecosystem also includes trusted advisers like these, who are actively helping organizations plan, design and implement strategies to enable sustainable growth:

Learn more about breakthrough work being done by our sustainability partners on Microsoft AppSource.

What’s next?
Microsoft Cloud for Sustainability availability coincides with Hannover Messe 2022. Watch for news and announcements around this keystone industry event — and stay tuned for additional solutions and capabilities.

Tags: Cloud, Microsoft Cloud for Sustainability, sustainability

Source

Continue Reading

Microsoft

Babylon.js 5.0: Key Engine Advancements – Part 3

Our mission is to create it one of the most powerful, beautiful, and simple web rendering engines in the world. The latest Babylon.js 5.0 engine packs a ton of new improvements to help you create stunning experiences. Unlimited Morph Targets No matter what you call them, Blend Shapes, Shape Keys, or Morph Targets, Babylon.js 5.0 adds…

Published

on

By

Our mission is to create it one of the most powerful, beautiful, and simple web rendering engines in the world. The latest Babylon.js 5.0 engine packs a ton of new improvements to help you create stunning experiences.

Unlimited Morph Targets

No matter what you call them, Blend Shapes, Shape Keys, or Morph Targets, Babylon.js 5.0 adds rocket fuel to your ability to use influenced vertex positions. This new feature now gives you literally unlimited amounts of Morph Targets. Want to have a complex animated face with thousands of Morph Targets to get that perfect expression? Now you can, all in the web, all for free!

See it in action here: Unlimited Morph Targets Demo

Learn more: Unlimited Morph Targets Documentation

YouTube Series: Tech Artist’s Journey YouTube Playlist

Order Independent Transparency

Rendering transparent objects is complicated! The Babylon.js Platform has always strived to make it as easy as possible to help you inform the system of rendering order, alpha index, run depth-prepasses, and much more, so your scene can look correct. With Babylon.js 5.0 we’ve wrapped a bow on it all. All of the complexity of rendering transparent objects can now disappear with one single, simple line of code:

Try it out: Order Independent Transparency Demo

Learn More: Order Independent Transparency Documentation

WebXR Advancements

WebXR is an incredible web standard allowing web developers to create amazing cross-browser XR experiences. Using WebXR to add a mobile AR component to your web site can be a simple and fun way to engage your readers/users even further. While the technology to render world-locked 3D objects has existed in Babylon.js for some time, Babylon.js 5.0 steps the beauty-factor up several notches with the introduction of Light Estimation. This powerful yet easy-to-use new feature allows your Babylon.js scenes to estimate the light in your real-world location and automatically match the lighting and shadows of your virtual world-locked object. This creates a cutting-edge level of immersion between the physical and digital worlds…and it’s all here in Babylon.js…all for free! Babylon.js 5.0 also adds support for WebXR image tracking and WebXR Layers!!!

Check it out on your Android Phone: Light Estimation Demo, Image Tracking Demo

Learn More: Light Estimation Documentation

glTF Updates

The Babylon.js Platform prioritizes support for the absolute latest and greatest advancements to the glTF file format. This means every new version of Babylon.js unlocks new beautiful advancements in rendering capabilities, and Babylon.js 5.0 turns up the heat! With full support for KHR_materials_volume, KHR_materials_transmission, and KHR_materials_ior, you can now render some absolutely STUNNING visuals!

Check it out: KHR_materials_volume Demo

Learn More: KHR_materials_volume, KHR_materials_transmission, KHR_materials_ior

Mixed Reality Toolkit for Babylon.js

Babylon.js 5.0 also adds updated support for the world’s most advanced 3D interface component library, Mixed Reality Toolkit. This advanced library makes it incredibly easy to add advanced XR UX elements into your Babylon.js scenes such as: holographic slates, 3D Sliders, Touch Holographic Buttons, Touch Mesh Buttons, and much much more!

Check it out: MRTK Demo

Learn More: MRTK Documentation

Material Plugin Manager

When it comes to creating real-time shaders power, performance, and flexibility are critical! Babylon.js 5.0 brings introduces a brand new feature that doubles down on all of three. The Material Plugin Manager gives you the ability to add custom code to any Babylon.js shader. This means that you can fully customize any advanced shader, such as PBR, to go even further. The Material Plugin Manager provides developers with the flexibility to fully customize the power, performance, and look of any shader!

Check it out: Material Plugin Manager Demo

Learn More: Material Plugin Manager Documentation

Much Much More

Wow that’s a lot, but that’s only the tip of the iceberg! Improved Shadow Performance, Vertex Animation Textures, a brand-new Build System, there’s more to Babylon.js 5.0 than you can imagine! Want a full view of everything that’s new? For a full list of features, enhancements, and fixes you can head on over here.

Babylon.js 5.0 launches the Babylon.js platform to incredible new heights and we cannot wait to see you reach for the stars with it!

Source

Continue Reading

Microsoft

In their mission to diversify STEM education, twin brothers use Windows 11

Twins Miles and Malik George are almost always in sync. They graduated at the top of their high school class as co-valedictorians. At MIT, these bioengineering students embraced and expanded upon their love of science. They were also in multiple diverse groups on campus such as Nu Delta Fraternity, The Standard, and Laureates and Leaders.…

Published

on

By

Twins Miles and Malik George are almost always in sync.

They graduated at the top of their high school class as co-valedictorians.

At MIT, these bioengineering students embraced and expanded upon their love of science. They were also in multiple diverse groups on campus such as Nu Delta Fraternity, The Standard, and Laureates and Leaders.

This last program is dedicated to helping under-represented students get Ph.D.s or M.D./Ph.D.s and has a selective entry process. The two fondly remembered the program as instrumental in shaping their academic careers.

They worked with MIT Admissions as Admissions Ambassadors to increase the number of underrepresented students that apply to and attend the university. On campus and virtually, they worked in several biological engineering labs. They’re about to graduate and will be pursuing Ph.D.s in Biological Engineering at MIT.


They’re both passionate about bringing STEM (science, technology, engineering and math) to under-served communities through hundreds of funny and informative lessons posted to TikTok and other social media. Their mix of memes, dances and trivia reach all kinds of audiences. They teach what they find exciting about science.

“The more curious you are about one subject, the more you learn about that subject, the more curious you become about everything else,” Miles says. “Curiosity is the reason why people keep innovating. And so as long as people are curious, people will keep learning.”

“Curiosity leads to solutions, you know?” Malik adds.

The brothers will host a private virtual education event for students May 17 in partnership with Microsoft Stores. This session will reach 10,000 students and will feature an inspirational fireside chat, STEM demonstration and interactive Q&A.

The twins strive to be role models for the next generation, to inspire them to follow their dreams.

“In high school we did a lot of science fairs. Being able to count on your hand how many people look like you in a room of over a hundred people, it’s pretty sad,” Malik says. “As we became involved in science ourselves, we wanted to make sure that people saw there are people that look like us in the field and that they can and should feel welcome to do so as well.”

They’re both PC gamers who enjoy comic book universes and socializing with their many friends.

They are part of a tight-knit family, helping their parents with gardening and jigsaw puzzles, watching movies together and doting on the senior Shih-tzu (who is the fifth member of their household).

But they are also individuals.

Malik is the “explainer.” As his brother shares, “He’s going make sure that if he’s telling you about something, you know everything that there is about the topic and he’s going make sure you understand it at the end of the day.”

“If I’m the explainer, then Miles is the convincer,” says Malik. “You know, he can summarize any topic – no matter how advanced – in a couple sentences to any age group and they’ll understand it.”

This works well when they’re doing presentations, which have reached more than 1,000 students remotely (ranging in age from late elementary school to high school seniors) since January 2021. They’ve been getting more interest about K-12 presentations and plan to continue those.

“I’ll do the intro. He does methods and results. I do the conclusion. He gives you the scientific know-how, how to learn. Then I bring it back at the end,” Miles says.

They also have different work styles – though both are also lifetime PC users. For as long as they can remember, they’ve always been on Windows, starting from their childhood.

“If you were to look at my desktop, you will see at least three applications open at once. If you look at Miles’ desktop, you’ll see one application open, but he’ll have three desktops that he’ll switch between,” Malik says.

Multiple desktops are one of Miles’ favorite Windows 11 features.

“I have one program that I’m focused on. When I’m done focusing on it, I’ll switch to another desktop and that’s what I’m working on then,” he says. “Each assignment gets its own desktop, and I will get to it when I get to it.”

They’ve discovered other Windows 11 features that make them even more efficient.

“As a student, I am constantly searching through emails, especially through keyword search,” Malik says. “I globally search by who sent it or a keyword and it will just show up right there. And I can read it or I can click it and reply from the same place. Windows 11 really takes away flipping back and forth between things. And then anything that you don’t have open, you can also just go through the Start menu.”

They also make great use of Snap Assist.

“I can have an essay snap to the right on Word. I can have some internet research article on the left,” Malik says. “And then if I need to check my email, it would just pop up in the center and I don’t have to cover what I was already working on.”

They like that they can tailor Windows 11 to what works best for each of them.

“It really feels like a personalized experience when I’m online. And it really visually is a much better experience than what I’m used to,” Miles says. “As a researcher, I’m used to a lot of diagrams, a lot of graphs. It really combines multitasking with this beautiful element of note taking and annotating directly on the screen.”

Source

Continue Reading

Trending

Copyright © 2021 Today's Digital.