Code Monkey home page Code Monkey logo

bits-manager's Introduction

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

What is BITS Manager

BITS Manager is a sample GUI tool for examining and creating BITS (Background Intelligent Transfer Service) uploads and downloads. It uses information from the Calling into BITS from .NET and C# using Reference DLLs documentation to create a program that can

  • list all jobs and all files in each job
  • create new jobs and add file to jobs
  • examine job and file settings

Annotated BITS Manager screen

The different states

Each job is marked with an icon that represents its state. See the Life Cycle of a BITS Job for details on the different BITS jobs states that are possible and how they transition from one to the other.

BITS State Icons
Starting States
Suspended 😴
Action States
Queued πŸ™‚
Connecting 😡
Transferring 😏
Transient Error 😬
Transferred States
Error 😑
Transferred 😁
Final States
Acknowledged 😎
Cancelled 😧

Once a job is in a final state, it will no longer be enumerated. Jobs that had been enumerated but which no longer show up in an enumeration will be marked with a ⧆ character.

Building BITS Manager

To build your own verison of BITS Manager

  • download all of the source code including the solution (.SLN) files
  • open the solution file in Visual Studio. The solution has been tested on version 15.8.9. Visual Studio must include the .NET desktop development option.
  • from the menu, select Buildβž”Solution to build the project

A quick tour of the BITS Manager code

The list of jobs is set up in MainWindow.xaml.cs in the RefreshJobsList function. This function calls EnumJobs on the main BITS IBackgroundCopyManager object. The RefreshJobList makes a series of JobViewControl XAML User Controls, one control for each BITS job.

The JobViewControl control displays a single job's name and description and sets the state image based on the state. When, in the MainWindow's list of JobViewControls, a single JobViewControl is selected, the JobDetailViewControl is updated with that job

The JobDetailViewControl control, when given a BITS job to display, performs three tasks.

  • The SetJob method updates the display with details about the job (for example, the owner, the current status, job flags).
  • The ListBITSJobFiles method updates the list of files associated with the job. It does this by creating new FileDetailViewControl objects, one per file.
  • The EnableActionButton method picks which buttons (Cancel, Complete, Pause, Resume) are enabled based on the current job state

The FileDetailViewControl class contructor, when given a BITS job and file, will update the control with details about the job.

The MainWindow class also contains

  • the Timer and corresponding Timer_Tick function that updates the job list and keeps it fresh
  • the UI code to handle ^K^V and menu requests
  • complete code to handle quick file downloads

bits-manager's People

Contributors

diego-perez-botero avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar petersmithredmond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bits-manager's Issues

Application crashed after start quick download

Windows Server 2012R2
after add quick download job it's gave out some of COM exception windows, and then I found this in Apllication Events Log:

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
   at BITSReference5_0.IBackgroundCopyJob5.GetProperty(BITSReference5_0.BITS_JOB_PROPERTY_ID, BITSReference5_0.BITS_JOB_PROPERTY_VALUE ByRef)
   at BITSManager.JobDetailViewControl.SetJob(BITSReference1_5.IBackgroundCopyJob)
   at BITSManager.MainWindow.OnJobSelectionChanged(System.Object, System.Windows.Controls.SelectionChangedEventArgs)
   at System.Windows.Controls.SelectionChangedEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.ListBox.OnSelectionChanged(System.Windows.Controls.SelectionChangedEventArgs)
   at System.Windows.Controls.Primitives.Selector.InvokeSelectionChanged(System.Collections.Generic.List`1<ItemInfo>, System.Collections.Generic.List`1<ItemInfo>)
   at System.Windows.Controls.Primitives.Selector+SelectionChanger.End()
   at System.Windows.Controls.Primitives.Selector+SelectionChanger.SelectJustThisItem(ItemInfo, Boolean)
   at System.Windows.Controls.Primitives.Selector.OnSelectedIndexChanged(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs)
   at System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex, System.Windows.DependencyProperty, System.Windows.PropertyMetadata, System.Windows.EffectiveValueEntry, System.Windows.EffectiveValueEntry ByRef, Boolean, Boolean, System.Windows.OperationType)
   at System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty, System.Object, System.Windows.PropertyMetadata, Boolean, Boolean, System.Windows.OperationType, Boolean)
   at System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty, System.Object)
   at BITSManager.MainWindow.RefreshJobList()
   at BITSManager.MainWindow.Timer_Tick(System.Object, System.EventArgs)
   at System.Windows.Threading.DispatcherTimer.FireTick(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.MessageBox(System.Runtime.InteropServices.HandleRef, System.String, System.String, Int32)
   at System.Windows.MessageBox.ShowCore(IntPtr, System.String, System.String, System.Windows.MessageBoxButton, System.Windows.MessageBoxImage, System.Windows.MessageBoxResult, System.Windows.MessageBoxOptions)
   at BITSManager.App.App_DispatcherUnhandledException(System.Object, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs)
   at System.Windows.Threading.Dispatcher.CatchException(System.Exception)
   at System.Windows.Threading.Dispatcher.CatchExceptionStatic(System.Object, System.Exception)
   at System.Windows.Threading.ExceptionWrapper.CatchException(System.Object, System.Exception, System.Delegate)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at BITSManager.App.Main()```

The background access settings of the job's owner app prevent the job from transferring at this time

First and foremost, thanks for this managed sample, it was a great help to kick-start my BITS journey.

My app based on BITS-Manager and BITS-Manager itself worked great, but when I packaged my app with MSIX, things started behaving strangely. Every background copy job started from the packaged app transitions into the BG_JOB_STATE_TRANSIENT_ERROR state immediately and stays that way until the app is closed or becomes inactive/minimized. I was able to reproduce this issue with the BITS-Manager app in a packaged environment.

Using bitsadmin /list /allusers /verbose, I got this:

GUID: {A8C6001C-182D-424B-86DC-6C8E131E185B} DISPLAY: 'Download an update'
TYPE: DOWNLOAD STATE: TRANSIENT_ERROR OWNER: ....
PRIORITY: NORMAL FILES: 0 / 1 BYTES: 0 / UNKNOWN
CREATION TIME: 9/2/2022 11:33:08 AM MODIFICATION TIME: 9/2/2022 11:33:58 AM
COMPLETION TIME: UNKNOWN ACL FLAGS:
NOTIFY INTERFACE: UNREGISTERED NOTIFICATION FLAGS: 3
RETRY DELAY: 600 NO PROGRESS TIMEOUT: 1209600 ERROR COUNT: 0
PROXY USAGE: PRECONFIG PROXY LIST: NULL PROXY BYPASS LIST: NULL
ERROR FILE:    ...
ERROR CODE:    0x8020006e - The background access settings of the job's owner app prevent the job from transferring at this time.
ERROR CONTEXT: 0x00000002 - The error occurred in the Background Intelligent Transfer Service (BITS) queue manager.
DESCRIPTION:
JOB FILES:
        0 / UNKNOWN WORKING ...
NOTIFICATION COMMAND LINE: none
owner MIC integrity level: MEDIUM
owner elevated ?           false

Peercaching flags
         Enable download from peers      :false
         Enable serving to peers         :false

CUSTOM HEADERS: NULL

I tried to set the job's priority, but it didn't help. I also had a hunch that I might need to enable some capability in the MSIX manifest, but I haven't found anything. I also tried to use the BackgroundDownloader from my WPF app, but it looks like UWP only.

Is it a known behavior? Anything I can do to make it transfer bites while the packaged app is running? Thanks in advance πŸ‘

"Range" header missing in BITS download request randomly

I have implemented a web api server to handle BITS download requests according to this. At the server end, the first Get request header does not contain the key Range sometimes.

BITS keeps retrying and finally the job reaches Error-State. For smaller files ~2MB this works properly if entire file is sent in this case, but for file bigger files (~350 MB) BITS keeps retrying. Is it the expected behavior or BITS expects some other Response here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.