【发布时间】:2018-01-18 04:51:04
【问题描述】:
我是 C# 新手。
我想问的是我创建一个表单并将其编译成 dll 并尝试从另一个应用程序(从公司应用程序)调用它。
我想问的是,当我尝试第一次打开我的表单时,需要一段时间(比如 1-2 分钟)然后我关闭表单(不是应用程序)并重新尝试再次打开表单第二次它比第一次快得多。
但是如果我完全关闭应用程序并第一次重新打开我的表单需要一段时间(如 1-2分钟)。
对于dll本身,都是选择数据库。代码如下
public partial class Genre : Form
{
SqlConnection myConnection = new SqlConnection(class.Conn);
DataTable dt_main = new DataTable();
Bitmap gbr_inf = new Bitmap(Properties.Resources.info_icon, 25, 25);
Bitmap gbr_error = new Bitmap(Properties.Resources.close, 25, 25);
RepositoryItemComboBox repositoryItemComboBox1 = new RepositoryItemComboBox();
RepositoryItemComboBox repositoryItemComboBox2 = new RepositoryItemComboBox();
public Genre()
{
InitializeComponent();
repositoryItemComboBox1.ButtonClick += RepositoryItemComboBox1_ButtonClick;
repositoryItemComboBox2.ButtonClick += RepositoryItemComboBox2_ButtonClick;
}
private void Genre_Load(object sender, EventArgs e)
{
SDB();
fill_repo();
}
public void SDB()
{
SqlCommand command = new SqlCommand();
SqlDataAdapter adapter = new SqlDataAdapter();
try
{
dt_main.Clear();
myConnection.Open();
command.Connection = myConnection;
command.CommandText = "Select * from Genre with (nolock) order by code";
adapter.SelectCommand = command;
adapter.Fill(dt_main);
gridControl1.DataSource = dt_main;
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
}
finally
{
myConnection.Close();
}
}
public void fill_repo()
{
DataTable dtrepo = new DataTable();
dtrepo.Clear();
dtrepo = dt_main.Copy();
for (int i = 0; i < dtrepo.Rows.Count; i++)
{
string code = dtrepo.Rows[i]["code"].ToString();
string genre = dtrepo.Rows[i]["genre"].ToString();
if (!repositoryItemComboBox1.Items.Contains(code))
{
repositoryItemComboBox1.Items.Add(code);
}
if (!repositoryItemComboBox2.Items.Contains(genre))
{
repositoryItemComboBox2.Items.Add(genre);
}
}
}
private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "code" && view.IsFilterRow(e.RowHandle))
{
e.RepositoryItem = repositoryItemComboBox1;
}
if (e.Column.FieldName == "genre" && view.IsFilterRow(e.RowHandle))
{
e.RepositoryItem = repositoryItemComboBox2;
}
}
}
似乎是什么问题?
【问题讨论】:
-
我没有看到 DevExpress 的链接。这就是 DLL 中的全部内容吗?第一次需要加载库的代码。如果有很多依赖项做某事,那将需要时间。但是超过一分钟?您是否尝试过逐行调试以查看发生了什么?
-
如果您从数据库中选择记录,应用程序在第一次运行时运行时间较长是正常的;之后,记录已经在缓存中,因此可以在接下来的运行中更快地选择它们。
-
@SamiKuhmonen 好吧,对于导入,我不会在这篇文章中输入它。它有 13 个依赖项,主要是 devexpress。调试我没有看到任何错误
-
@SebastianHofmann 我知道。让我给你一个表格a和表格b的例子。与上面的表格a类似,表格b比表格a更有选择。假设我第一次打开应用程序并首先打开我的表单 A(需要 1 分钟)然后我打开我的表单 B(需要不到 1 分钟)。反之亦然。如果我第一次打开应用程序并首先打开我的表格 B(需要超过 1 分钟)然后我打开我的表格 A(需要不到 1 分钟)