.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

AppDomain.Unload called multiple times?

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :.NET Framework



     In a simple console app, I created a separate AppDomain (name: ad2)  to do some work.  In this AppDomain, I created a separate worker thread  and deliberately put the thread to sleep for long time (2 mins) in the Finally block.


      I also subscribed to the ad2’s Unload event  to do some logging.


      Immediately after calling the worker method, I called the AppDomain.Unload(ad2) in the main thread.  Because of the long Thread.Sleep() in the worker thread finally block, a CannotUnloadAppdomainException was thrown when calling AppDomain.Unload(ad2).

View Complete Post

More Related Resource Links

DataGrid ValidationRule or IDataErrorInfo validation code called multiple times for each data change

Following my enquiry regarding a problem in Datagrid validation, for which managing exceptions is apparently a problem, I tested the two other methods: using validation rules, or implementing the IDataErrorInfo interface. I ran into other problems there, more insidious this time. This has been done on Windows7 (32-bit), .NET 4.0.30319. 1) IDataErrorInfo When this interface is implemented, the this[string columnName] property is called four times for each modification: two times before the cell enters edit mode (with the old value in the corresponding property) two times when the new value has to be validated (with the new value) It strikes me as not really efficient, is there something wrong with my code? Here's the C# part: using System; using System.Windows; using System.Collections.ObjectModel; using System.ComponentModel; namespace DataGridTest2 { public partial class MainWindow : Window { ObservableCollection<User> users; public MainWindow() { InitializeComponent(); users = new ObservableCollection<User>() { new User { Name = "Teddy", Age = "2" }, new User { Name = "Avi", Age = "19" } }; datagrid.ItemsSource = users; datagrid.Focus(); } } public class User : INotifyPropertyChanged, IDataErrorInfo { string name; public string Name

application_start event called multiple times in MVC application

hi, In my MVC application ,I am updating my web.config at runtime through application_start event.So, ideally it should be done only when the application is started.BUT in MY mvc application the application_start event of global.asax is being called multiple times , even when i have not restarted the application. Its being repetadly called when i am calling different actions , so the webconfig is repetedly updating & making my application very very slow. Can you please let me know , what's the reason & how to handle this .   Thanks in advance gbhatnagar    

CacheMetadata being called multiple times


I'm going through the exercises of Bruce Bukovics new WF4 book and in one of his examples, the results he's generating are different from the results I'm getting. He states for an instantiated instance of an activity, if it's executed multiple times, the CacheMetadata is only called once. I'm seeing it called for each execution of the activity I'm making. Is he wrong or am I not interpreting the results correctly.

Here's a link to the solution containing the custom activity, designer, and testing console app:

Any guidance would be appreciated. Thanks!

Blades Don't Need Reloading...

AppDomain.Unload effects Unable to evaluate expression because the code is optimized or a native fra

Hello, I create a custom AppDomain.Create().  I registered the Unhandled Exception Event from my custom AppDomain. In the Unhandled Exception Event i try to Unload my AppDomain with AppDomain.Unload. But this effects a "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." Have anyone a idea what i can do against this behaviour. greetints

Insert Same Record Multiple Times.

I have a simple form that inserts a record into a SQL table. The fields are: SerialNumTagNumPONumLocationAddressDescription   This works great. However, I have now been asked to have the form insert x number of records at one time. They want to be able to fill out the following fields: PONumLocationAddressDescription and then have texbox where they can add a number and have that number of the same record inserted.    I hope this makes sense.

Invoke Delay Activity multiple times

HI! I am using Workflow Foundation workflows with sharepoint lists. I have a state machine workflow. One state of workflow has 2 event driven activities, one is waiting for task change and other is waiting for delay of 1 day. What i need is to send email if delay of 1 day is elapsed and send this email every day. But Delay activity is invoked only once. How can i change it so that it can be invoked multiple times. Shabih

Data Binding a DataGrid to a list fetch the same data multiple times

Hi, I'm using DataGrid to show data through data binding. My data are provided in a list. The setup I have is the following: DataGrid "binded" to the default view of my list that implement IList<T> and IList interfaces (MyList<T> : IList<T>, IList, INotifyCollectionChanged)             CollectionViewSource.GetDefaultView(_myList);             // Set the data context             DataContext = view; T: is here my 'business object' that hold the data, called 'MyRow'. Then the columns of the DataGrid are bound to public properties of 'MyRow' object. MyRow class has a public property of type 'object' (public object data[int index]) and first column of datagrid is bound to myRow.data[0], second column is bound to myRow.data[1] and so on.   When the datagrid is displayed, databinding kick in and my data are showed in the control. The issue I'm having is that data fetching is very repetitive even for the same rows. For example for a datagrid with 20 visible rows, the first row is fetched multiple times even if the datagrid is not resized or moved. I put break point inside my list (MyList<T> into This[T] property (public T this[int index]) and i got multiple hits into the property for the same index. Fetc

How to use a Resource multiple times in a window

  Hi, I want to create a resource and use this resource several times in one window. The example shows a simple thing what i want to accomplish. However, this way it does not work, because the  resource can only be loaded once. Is there a way to specify a resource that can be loaded more than once? <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <StackPanel x:Key="GG"> <Button Width="100" Height="23" Content="Click"> </Button> </StackPanel> </Window.Resources> <Grid> <ContentControl Content="{StaticResource GG}"></ContentControl> <ContentControl Content="{StaticResource GG}" HorizontalAlignment="Left" ></ContentControl> </Grid> </Window>

ScriptManager CompositeScript Error: A script reference cannot be included multiple times in composi

I am getting the following error using the CompositeScript feature of the ScriptManager.  I have ScriptManagerProxy in several different usercontrols that use CompositeScript to add whatever JS files they need.  Sometimes there are duplicates which would get removed by the script manager, but that is not happening with the Composite Scripts.  Looking at the stack trace, it calls RemoveDuplicates but for some reason it doesn't do so.  Is this a bug?  Is there a workaround or a hotfix? Thanks! A script reference cannot be included multiple times in composite script references. Stack Trace: [InvalidOperationException: A script reference cannot be included multiple times in composite script references.]   System.Web.UI.ScriptManager.RemoveDuplicates(List`1 scripts) +698   System.Web.UI.ScriptManager.RegisterScripts() +328   System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +113   System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8695102   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1029

WS-ReliableMessaging: Message sent multiple times when payload is large

Environment: .NET WCF client to .NET WCF service using WS-ReliableMessaging   Description: I am sending rather large message (~ 50 mb) using a .NET WCF client to a .NET WCF service. I have enabled WS-ReliableMessaging. This results in the following message flow: http://dl.dropbox.com/u/1373661/messageflow.png The flow shows that the payload message is sent with an interval of less than a second. Why is this? The problem doesn't seem to happend when sending small messages. The client side App.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <customBinding> <binding name="OiosiHttpBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"> <reliableSession flowControlEnabled="false" inactivityTimeout="01:00:00" maxPendingChannels="32" maxTransferWindowSize="32" ordered="true" /> <!-- <security defaultAlgorithmSuite="Default" authenticationMode="MutualCertificate" requireDerivedKeys="false" securityHeaderLayout="Strict" includeTimestamp="true" keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeE

AppDomain Unload does corrupt Thread Pool

Hi,I was just trying to run a simple scenario:1. Create AppDomain2. Use up all Worker threads from Thread Pool 3. Unload AppDomain before the worker threads have finished.4. Try to queue another WorkItem in your default or some other AppDomainResult: The .NET thread pool is dead because there are no threads left for the other AppDomain. ThreadPool Threads are not given back to the thread pool when an AppDomain.Unload is performed. I think it is ok to not kill the threads (reliability) but what is not ok is that there are no threads left for other AppDomains. An AppDomain unload should increase the number of worker/io completion port threads which are currently running inside the to be unloaded AppDomain to ensure that you do not run out of threads after 2-3 days of regular operation when some AppDomains where created and destroyed in the meantime.This will eat up your thread pool quite fast.Sample Code to reproduce:using System;using System.Collections.Generic;using System.Text;using System.Threading;using System.Diagnostics;namespace ThreadPoolAndAppDomain{    [Serializable]    public class Worker    {       public Worker()       {}       int nQueuedItems = 0;              public void QueueWorkItems(int n)       {           for (int i = 0; i < n; i++)           {               ThreadPool.QueueUserWorkItem(delegate(object state)               {                   lock (this) 

toolbox shows items multiple times

My tool box shows the same tools about 12 times.  This is for all of them and for all categories.  I tried repairing it but it didn't work. 

Adding a table or view multiple times when building a query with BI Report Designer and Report Build

How can I add a table/view multiple times to a single query by using BI Report Designer or Report Builder 3.0? In Report Designer I managed (workaround) to add one table multiple times by creating multiple Named Queries and having the same SELECT. Still I don't know how to add one table multiple times in Report Builder 3.0.

How to get # of times a batch has executed within the batch which is being executed multiple times u


Go with the count argument is great if I just want to execute a batch multiple times.  I want to replace coding which is currently using WHILE loop with GO but I need to find out # of times the batch has executed within the batch which is being executed using GO with the count argument.  How does SQL Server keep track # of times a batch executed so far?

list column getting created multiple times.



I am trying to add a list column to a document library. When I am running the application multiple times, the list column is also getting created multiple times. If the list column exist, i dont want to recreate the column, but only assign the value to that list column.

This is the code i have used:


SPView curview = list.DefaultView;
SPViewFieldCollection fieldCol = curview.ViewFields;
if (!fieldCol.Exists("Custom Column"))
AddField("FilesCount", SPFieldType.Text, list.Fields);
fieldCol.View.DefaultView = true;
curview.ViewFields.Add("Custom Column");
SPFolder subFolder;
int mouas =5;
subFolder.Item["Custom Column"] = mouas;

private static SPField AddField(string title, SPFieldType type, SPFieldCollection fields)
if (!fields.ContainsField(title))
 fields.Add(title, type, false);                  
return fields.GetField(title);


How to avoid the duplicate creation of column, and assign the value to column, if the column exists?

I found that if the newly created column name is having white spa

WPF Datagrid SelectionChanged event is triggering Multiple times while loading the rows.



When i use DataGridComboBoxColumn in my WPF DataGrid, the DataGrid SelectionChanged event is triggering multiple times based on the number of rows while loading the rows in the WPF DataGrid.

How can i stop this? Because of this I am facing Performance issue.



Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

Assembly is not unloaded on AppDomain unload


In order to attempt to unload an assembly I use the following code. Yet the assembly is not unloaded. The second call to Execute is performed yet it shouldn't be available anymore should it?

Also the HandlerOne.dll is still locked. As I load it from memory I wonder why it is still locked


    // Copy assembly in memory to prevent file lock
    System.IO.StreamReader reader;
    byte[] buf;
    using ( reader = new System.IO.StreamReader( "HandlerOne.dll", System.Text.Encoding.GetEncoding( 1252 ), false ) )
      buf = new byte[reader.BaseStream.Length];
      reader.BaseStream.Read( buf, 0, System.Convert.ToInt32( reader.BaseStream.Length ) );

    // Create a seperate AppDomain
    // Load the handler
    AppDomain d = AppDomain.CreateDomain( "one" );
    Assembly a = d.Load( buf );
    Type typ = a.GetType( "HandlerLib.HandlerOne", <
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend