C# 使用多个窗体调试项目中的单个winforms
如何在项目中使用多个winforms运行单个winform,而不运行整个项目C# 使用多个窗体调试项目中的单个winforms,c#,winforms,entity-framework-6,C#,Winforms,Entity Framework 6,如何在项目中使用多个winforms运行单个winform,而不运行整个项目 using System.Data; using System.Drawing; using System.Linq; using Syncfusion.Windows.Forms; namespace Desktop { public partial class WarnaForm : MetroForm { private DataTable table; public WarnaForm()
using System.Data;
using System.Drawing;
using System.Linq;
using Syncfusion.Windows.Forms;
namespace Desktop
{
public partial class WarnaForm : MetroForm
{
private DataTable table;
public WarnaForm()
{
InitializeComponent();
_initializeData();
_initializeGridGrouping();
}
private void _initializeData()
{
table = getTable();
/*
using (HMERPEntities context = new HMERPEntities())
{
var queryDaftarSemuaWarna = context.warna;
foreach (var w in queryDaftarSemuaWarna.ToList())
{
DataRow rowNew = table.NewRow();
rowNew["No"] = w.warna_id;
rowNew["Nama"] = w.nama;
table.Rows.Add(rowNew);
table.AcceptChanges();
}
}*/
}
public DataTable getTable()
{
DataTable table = new DataTable();
table.Columns.Add("No", typeof (long));
table.Columns.Add("Nama", typeof (string));
return table;
}
private void _initializeGridGrouping()
{
gridGroupingControl1.DataSource = table;
}
}
}
对于未连接到数据库的winform,我使用immiDate窗口执行此操作:
但当我将代码与实体框架连接(取消EF部分的注释)放在一起时,它会给我一个错误
类型的第一次机会例外
中出现“System.Threading.ThreadAbortException”
EntityFramework.dll计算需要临时运行线程。
使用“监视”窗口执行评估
非常感谢,
附言:
我正在使用:
-visual studio CE 2013
-c#winforms与.net 4.5版
-windows 7您可以从程序.cs向窗体添加临时调用,如下所示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Temporarily add this...
Application.Run(new frmYourForm());
Application.Run(new frmMain());
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序1
{
静态类程序
{
///
///应用程序的主要入口点。
///
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//暂时添加此。。。
运行(新的frmYourForm());
运行(新的frmMain());
}
}
}
我建议在HMERPEntities
类中添加这样的方法,其中SomeEntityType
将替换为实际的“warna
”对象类型:
public List<SomeEntityType> GetWarna() {
System.Diagnostics.Debugger.NotifyOfCrossThreadDependency();
return warna.ToList();
}
更改您的启动表单?是否存在引发异常的特定属性?尝试调用调试器
NotifyOfCrossThreadDependency()
在属性的get方法中,就在返回值之前,@Jeremy的可能重复项您指的是像Nick Allan指出的那样在Program.cs中更改代码?我已经试过了,但如果我能从immidate窗口运行它会更好。thx.@YusrilMaulidanRaji是的,我以前读过这篇文章,试图更改调试器设置,但没有成功。我尝试过,但它会引发相同的错误。我会选择尼克·艾伦和杰里米的答案,因为这是最简单的答案。谢谢。
var queryDaftarSemuaWarna = context.GetWarna();