Export (0) Print
Expand All

XpsDocumentWriter.raise_WritingCompleted Method

.NET Framework 3.0
Raises the WritingCompleted event.

Namespace: System.Windows.Xps
Assembly: System.Printing (in system.printing.dll)

Not applicable.

Parameters

sender

The source of the event.

e

The event data.

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();
}

For the complete sample, see Saving an XPS Document Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft