我有一个.Net Framework#4.0应用程序使用WebRequest/WebResponse类生成大量Web请求,因为我看到它有内存泄漏(或者我做错了)我写了一些小的简单应用程序来演示这个:
class Program
{
public static void Main(string[] args)
{
while(true)
{
var webRequest = (HttpWebRequest)WebRequest.Create("http://www.gooogle.com");
Init(webRequest);
using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
{
var responseStream = webResponse.GetResponseStream();
responseStream.ReadTimeout = 30;
var streamReader = new StreamReader(responseStream, Encoding.UTF8);
var page = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
responseStream.Close();
responseStream.Dispose();
webResponse.Close();
Console.WriteLine("Done");
//GC.Collect();
}
}
}
private static void Init (HttpWebRequest webRequest)
{
webRequest.Method = "GET";
webRequest.Host = "www.gooogle.com";
webRequest.UserAgent =
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; …Run Code Online (Sandbox Code Playgroud) 我试图从其他文件加载WPF样式实际上从WPF自定义控件库,但我无法加载这里是我的解决方案.
该解决方案包含两个项目
WPF自定义控件库类型的WpfTestControls
WPF应用程序库类型的WpfTestApp,它引用了WpfTestControls
来自WPF应用程序库的MainWindow.xaml
<Window.Resources>
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
</Window.Resources>
<Grid>
<TextBox Height="50px" Width="100px" Style="{DynamicResource TempStyle}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
来自WPF自定义控件库的Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfTestControls;component/TextBoxStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
Run Code Online (Sandbox Code Playgroud)
来自WPF自定义控件库的TextBoxStyle.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="TempStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
我的AssemblyInfo.cs文件包含以下内容
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource …Run Code Online (Sandbox Code Playgroud)