为什么我编的C#的WINDOWS应用程序,运行时FORM不会显现出来,而是在后台运行?

spgoal 2002-05-20 11:22:09
我写了个链表类,然后想进行两个链表合并,再在FORM上显示出来,以前还可以的,但后来加了些代码后调试的时候就不能出现FORM,而是在后台运行
我发现不要调用public void ListInsert(int i,int e)函数就可以显示FORM,为什么?
部分代码:
namespace List
{
/// <summary>
/// Summary description for ListNode.
/// </summary>
// 结点类
public class ListNode
{
public ListNode(int NewValue)
{
Value=NewValue;
}
/// <summary>
/// 前一个
/// </summary>

public ListNode Previous;
/// <summary>
/// 后一个
/// </summary>
public ListNode Next;
/// <summary>
/// 值
/// </summary>
public int Value;
}
public class Clist
{
private ListNode Head; //头结点
private ListNode p; //当前结点

private int ListLen;
//*******************************************
public Clist()
{
Head=null;
p=null;
ListLen=0;
}
/// <summary>
/// 返回指定位置结点的值
/// </summary>
public int GetElem(int i)
{

ListNode move;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
int j;
move=Head;
for(j=1;j<i;j++)
//while(move!=null)
{
move=move.Next;
}
return move.Value;
}
return 0;
}
public void ListInsert(int i,int e)
{
ListNode NewNode=new ListNode(e);
ListNode q;
ListNode move;
int j;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
if(i==1)
{
Head.Previous =NewNode;
NewNode.Next =Head;
Head=NewNode;
ListLen++;
}
else
{
move=Head;
for(j=1;j<i;j++)
//while(move.Next!=null)
{
move=move.Next;
}
q=move;
NewNode.Next =q;
q.Previous =NewNode;
move.Next =NewNode;
NewNode.Previous =move;
move=NewNode;
p=NewNode;
ListLen++;
}


}
return;
}
/// <summary>
/// 判断链表中是否存在e
/// </summary>
public bool Isin(int e)
{
bool bl=false;
ListNode move;
int i;
move=Head;
while(move!=null)
//for(i=1;i<=ListLength;i++)
{
if(move.Value==e)
{
bl=true;
break;
}
else
{
move=move.Next;
}
}

return bl;
}
public string PrintList()
{

ListNode move;
string strtext="";
move=Head;
while(move!=null)
{
strtext=strtext + move.Value.ToString() + ",";
move=move.Next;
}
return strtext;
}
}
}

//*******************************
//form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using List;
namespace WindowsApplication3
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOut;
private Clist La;
private Clist Lb;
private System.Windows.Forms.Label lbl_a;
private System.Windows.Forms.Label lbl_b;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public void CreateList()
{
La=new Clist();
La.AppendNode(3);
La.AppendNode(5);
La.AppendNode(8);
La.AppendNode(11);
Lb=new Clist();
Lb.AppendNode(2);
Lb.AppendNode(6);
Lb.AppendNode(8);
Lb.AppendNode(9);
Lb.AppendNode(11);
Lb.AppendNode(15);
Lb.AppendNode(20);
return;
}
public string ex2_1()
{
Clist temp;
int La_len,Lb_len,i,e;
//CreateList();
La_len=La.ListLength;
Lb_len=Lb.ListLength;
temp=La;
for(i=1;i<=Lb_len;i++)
{
e=Lb.GetElem(i);
if(!temp.Isin(e))
{
La.ListInsert(La_len,e);
}
}

return La.PrintList();
}
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{

CreateList();
lbl_a.Text =La.PrintList();
lbl_b.Text =Lb.PrintList();
lblOut.Text =ex2_1();

}
}
}

...全文
131 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
spgoal 2002-05-22
  • 打赏
  • 举报
回复
问题解决,是那个函数里面的问题,谢谢大家
spgoal 2002-05-21
  • 打赏
  • 举报
回复
跟踪了,但一到NEW FORM就没戏了

对不起,这个代码是在天极那发过,吃了空格和XML,所以就变成这样了
spgoal 2002-05-21
  • 打赏
  • 举报
回复
按F8也可以呀,step by step,还是不行
wl_95421 2002-05-21
  • 打赏
  • 举报
回复
我说的跟踪
是指设置断点
然后一步步执行
spgoal 2002-05-20
  • 打赏
  • 举报
回复
//前插结点
public void ListInsert(int i,int e)
{
ListNode NewNode=new ListNode(e);
ListNode q;
ListNode move;
int j;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
if(i==1)
{
Head.Previous =NewNode;
NewNode.Next =Head;
Head=NewNode;
ListLen++;
}
else
{
move=Head;
for(j=1;j<i;j++)
//while(move.Next!=null)
{
move=move.Next;
}
q=move;
NewNode.Next =q;
q.Previous =NewNode;
move.Next =NewNode;
NewNode.Previous =move;
move=NewNode;
p=NewNode;
ListLen++;
}


}
return;
}
就是这个函数,一调用它就会这样
VegetableBird 2002-05-20
  • 打赏
  • 举报
回复
最大的可能是Form_Load中进入了无法结束的循环。

但是从贴出来的代码来看,缺了一些代码和注释,所以没有办法进行算法的分析了:)
wl_95421 2002-05-20
  • 打赏
  • 举报
回复
老兄
跟踪吧
以后写程序养成好习惯
你程序写的太乱
看的头晕
spgoal 2002-05-20
  • 打赏
  • 举报
回复
我试试,也没有百分百占用,但也占用了不少
wl_95421 2002-05-20
  • 打赏
  • 举报
回复
你运行程序的时候
看一下CPU的占用率
如果一直是百分百的话
肯定有死循环
否则就只有跟踪了

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧