Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XpsDocumentWriter.WritingCompleted Event

Occurs when a write operation finishes.

Namespace:  System.Windows.Xps
Assembly:  System.Printing (in System.Printing.dll)
public override event WritingCompletedEventHandler WritingCompleted

The following example shows how to use the WritingCompleted event.

private void SaveMultipleFixedContentDocumentsAsync(
             XpsDocumentWriter xpsdw, FixedDocumentSequence fds)
{
    _xpsdwActive = xpsdw;

    xpsdw.WritingCompleted +=
        new WritingCompletedEventHandler(AsyncSaveCompleted);

    xpsdw.WritingProgressChanged +=
        new WritingProgressChangedEventHandler(AsyncSavingProgress);

    // Write the FixedDocumentSequence as a 
    // collection of documents asynchronously.
    xpsdw.WriteAsync(fds);
}


// Cancel an async operation 
public void CancelAsync()
{
    _xpsdwActive.CancelAsync();
}
#endregion // Asynchronous Save Methods


#region Async Event Handlers
// 
// Create an "async operation complete" event handler
// for saving a FixedDocumentSequence 
// 
private void AsyncSaveCompleted(
             object sender, WritingCompletedEventArgs e)
{
    string result;
    if (e.Cancelled)          result = "Canceled";
    else if (e.Error != null) result = "Error";
    else                      result = "Asynchronous operation Completed";

    // Close the pakcage
    _xpsDocument.Close();

    if (OnAsyncSaveChange != null)
    {
        AsyncSaveEventArgs asyncInfo =
            new AsyncSaveEventArgs(result, true);
        OnAsyncSaveChange(this, asyncInfo);
    }
}

// 
// Create an "async operation progress" event handler for 
// monitoring the progress of saving a FixedDocumentSequence. 
// 
private void AsyncSavingProgress(
                object sender, WritingProgressChangedEventArgs e)
{
    _batchProgress++;

    if (OnAsyncSaveChange != null)
    {
        String progress =
            String.Format("{0} - {1}", e.WritingLevel.ToString(),
                          e.Number.ToString());
        AsyncSaveEventArgs asyncInfo =
            new AsyncSaveEventArgs(progress, false);
        OnAsyncSaveChange(this, asyncInfo);
    }

    // Call EndBatchWrite when serializing multiple visuals. 
    if ( (_activeVtoXPSD != null) && (_batchProgress == 3) )
        _activeVtoXPSD.EndBatchWrite();
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.