After the windows system wakes up from the sleep state, the application cannot continue to download

zhihao huang 20 Reputation points
2023-03-23T03:41:40.9566667+00:00

The application is in the process of downloading (using HttpClient). At this time, I hibernate the windows system and then wake up the system, but the application cannot continue to download (it is in Established). How can I continue to reuse the connection to continue downloading, or I need to recreate the httpclient object.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,346 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,205 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,426 Reputation points Microsoft Vendor
    2023-03-23T06:41:49.1833333+00:00

    Hi, welcome to Microsoft Q&A.

    Maybe you need to detect system wakeups to recreate downloads, or prevent the system from going to sleep.

    Based on System Wake-up Events, when the system automatically wakes up, it broadcasts the PBT_APMRESUMEAUTOMATIC event to all applications.

    A window receives PBT_APMRESUMEAUTOMATIC event through the WM_POWERBROADCAST message.

    You can determine whether the system is awakened by detecting the WM_POWERBROADCAST message.

    The code reference is as follows:

            private const int POWERBROADCAST = 0x0218;
    
            protected override void WndProc(ref Message m) {
                switch (m.Msg) {
    
                    case POWERBROADCAST:
    
                        if (m.Msg==18)
    
                            //recreate the httpclient object or doing something else.
    
                            this.Invalidate();
    
                        break;
                }
            }
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful