Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toast doesn't pop up after calling ToastNotifier.Show #2430

Open
autumngao opened this issue Dec 1, 2023 · 1 comment
Open

Toast doesn't pop up after calling ToastNotifier.Show #2430

autumngao opened this issue Dec 1, 2023 · 1 comment
Assignees
Labels
Pri2 Topic is in the second 25% of page views for the repo. uwp/prod Topic product is UWP-related. winrt-reference/tech Topic technology is WinRT-related.

Comments

@autumngao
Copy link

autumngao commented Dec 1, 2023

[Enter feedback here]

I create a consle application based on C++\Winrt , here is the source code.

int main(int argc, char* argv[])
{
	init_apartment();
	// Construct the toast template
	WCHAR szToast[1024] = { 0 };
	LoadString(GetModuleHandle(NULL), IDS_TOAST_MESSAGE, szToast, sizeof(szToast) / sizeof(WCHAR));
	winrt::param::hstring hStr(szToast);
	XmlDocument doc;
	doc.LoadXml(hStr);

	// Construct the notification
	ToastNotification notif{ doc };

	// And send it!
	auto notifier = ToastNotificationManager::CreateToastNotifier(_win32Aumid);

	auto notifierSetting = notifier.Setting();

	switch (notifierSetting)
	{
	case winrt::Windows::UI::Notifications::NotificationSetting::Enabled:
		notifier.Show(notif);
		break;
	case winrt::Windows::UI::Notifications::NotificationSetting::DisabledForApplication:
		break;
	case winrt::Windows::UI::Notifications::NotificationSetting::DisabledForUser:
		break;
	case winrt::Windows::UI::Notifications::NotificationSetting::DisabledByGroupPolicy:
		break;
	case winrt::Windows::UI::Notifications::NotificationSetting::DisabledByManifest:
		break;
	default:
		break;
	}

	return 0;
}

This code works well on windows11, but does not work on windows 10. If I add some operation code before return 0, such as cout << "what ever"<<endl; or sleep(100);, it can work on windows 10 too. It seems the application should wait for a moment after calling ToastNotifier.Show on windows 10.

Why does this happen? Is there any way to get the result of calling ToastNotifier.Show?

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

@issues-automation issues-automation bot added Pri2 Topic is in the second 25% of page views for the repo. uwp/prod Topic product is UWP-related. winrt-reference/tech Topic technology is WinRT-related. labels Dec 1, 2023
@autumngao
Copy link
Author

autumngao commented Dec 20, 2023

This is my toast template:

<toast>
    <visual>
        <binding template="ToastGeneric">
            <text>Title</text>
            <text>Text</text>
        </binding>
    </visual>
    <actions>
        <action content="Learn more" activationType="protocol" arguments="actionString:test"/>
    </actions>
</toast>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pri2 Topic is in the second 25% of page views for the repo. uwp/prod Topic product is UWP-related. winrt-reference/tech Topic technology is WinRT-related.
Projects
None yet
Development

No branches or pull requests

2 participants